[pymunk] Not working on OSX

Official forum for the Chipmunk2D Physics Library.

[pymunk] Not working on OSX

Postby maximile » Tue Aug 07, 2012 5:14 pm

Hi,

I'm trying to use pymunk on OS X and it's not working at all. Numeric properties on some objects don't get set properly. On bodies, mass is always some huge value and friction is always 0.0. Some things work, e.g. friction on a Circle.

I've tried this on Linux and everything works as expected.

Does anyone have any idea what could cause this? Lots of details follow. Thanks!

System: MacBook Pro, Intel, 32bit, OS X 10.6.8. Python 2.6.1. (Also tried with 2.5)

Code: Select all
>>> import pymunk
Loading chipmunk for Darwin (32bit) [/Library/Python/2.6/site-packages/pymunk/libchipmunk.dylib]
>>> body = pymunk.Body(10, 20)
>>> body.mass
1.4044477616111843e+306
>>> body.mass = 10
>>> body.mass
1.4044477616111843e+306
>>> body.friction = 10.0
>>> body.friction
0.0


The basic_test.py example logs this repeatedly:

Code: Select all
Aborting due to Chipmunk error: Body's position is invalid.
   Failed condition: cpfabs(v.x) != INFINITY && cpfabs(v.y) != INFINITY
   Source:chipmunk_src/cpBody.c:108


I tried with the 2.1.0 zip and the latest source from svn. Also tried replacing chipmunk_src with the latest Chipmunk from github, but that complained about missing files. I tried omitting '-O3', '-ffast-math', and '-fPIC' from the compiler flags. And I tried skipping the x86_64 build, as suggested in a few other places. Same result every time.
maximile
 
Posts: 157
Joined: Mon Aug 20, 2007 12:53 pm
Location: London, UK

Re: [pymunk] Not working on OSX

Postby aisman » Wed Aug 08, 2012 12:08 am

Have you ask the pymunk developers too?
Maybe they are the first choice for solving your problem.
Chipmunk4PB: The fastest way to write games together with PureBasic and the Chipmunk physics engine.
User avatar
aisman
 
Posts: 144
Joined: Tue Mar 04, 2008 2:21 am

Re: [pymunk] Not working on OSX

Postby maximile » Wed Aug 08, 2012 8:56 am

aisman wrote:Have you ask the pymunk developers too?


Thanks, I e-malled viblo as well.
maximile
 
Posts: 157
Joined: Mon Aug 20, 2007 12:53 pm
Location: London, UK

Re: [pymunk] Not working on OSX

Postby viblo » Wed Aug 08, 2012 10:13 am

OSX again! Just when I finally got it to work nice on 64bit OSX then ofc 32bit starts to mess up. Good news is I started on a new job just before the summer and here I have a OSX workstation, so this time I hope I will be able to better troubleshoot and fix this problem :)

I first tried compiling and running with the default python (OSX 10.7.4 and python 2.7 64bit) and it worked just fine. I tried force this python to run in 32bit mode with arch, but that doesnt seem to work? Anyway, I downloaded the latest 2.7 python from python.org and then redid the whole thing with python-32, and then I get the same behavior as you.

I will do some experiments to see if I can figure out a solution, but as I only have access to OSX while Im at work and I mostly do work when Im there it might take a little bit of time :) I will keep you updated when I find something.
http://www.pymunk.org - A python library built on top of Chipmunk to let you easily get cool 2d physics in your python game/app
viblo
 
Posts: 206
Joined: Tue Aug 21, 2007 3:12 pm

Re: [pymunk] Not working on OSX

Postby maximile » Wed Aug 08, 2012 4:03 pm

Thanks viblo, I'm glad you could reproduce the error. I'll keep playing too and let you know if I find anything.
maximile
 
Posts: 157
Joined: Mon Aug 20, 2007 12:53 pm
Location: London, UK

Re: [pymunk] Not working on OSX

Postby viblo » Fri Aug 10, 2012 9:48 am

Ok, after lots of debugging I found the problem! I will update pymunk trunk once I get home today with a workaround.

More in depth description of the problem:
in chipmunk_types.h we have
Code: Select all
#if (defined TARGET_OS_IPHONE) && (!defined CP_USE_CGPOINTS)
   #define CP_USE_CGPOINTS
#endif

#ifdef CP_USE_CGPOINTS
   #if TARGET_OS_IPHONE
      #import <CoreGraphics/CGGeometry.h>
   #elif TARGET_OS_MAC
      #import <ApplicationServices/ApplicationServices.h>
   #endif
   
   #if defined(__LP64__) && __LP64__
      #define CP_USE_DOUBLES 1
   #else
      #define CP_USE_DOUBLES 0
   #endif
#endif


However, on OSX 10.6 and onwards TARGET_OS_IPHONE will always be defined (but to 0 if target is not iPhone). This make CP_USE_DOUBLES be 0 in case we are on 32bit (__LP64__ not defined/true), and therefor cpFloat be float and not double.

pymunk cannot read out the size of a cpFloat in run time, so it will always assume a cpFloat is a double (as it doesnt make sense to use floats on a "real" computer, or at least that's what I thought).

slembcke: Is this really the intended behavior? Feels like a bug in the defines but maybe you always want to use CG POINTS on OSX?
http://www.pymunk.org - A python library built on top of Chipmunk to let you easily get cool 2d physics in your python game/app
viblo
 
Posts: 206
Joined: Tue Aug 21, 2007 3:12 pm

Re: [pymunk] Not working on OSX

Postby slembcke » Fri Aug 10, 2012 12:44 pm

D'oh. I've fixed a number of those where I've done that before. I thought I went through and found all of them. I guess not. I'll take a look at that when I get home from vacation.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: [pymunk] Not working on OSX

Postby viblo » Sat Aug 11, 2012 5:14 am

Ok, great :)

maximile: Ive checked in a fix for this problem in pymunk svn trunk.
http://www.pymunk.org - A python library built on top of Chipmunk to let you easily get cool 2d physics in your python game/app
viblo
 
Posts: 206
Joined: Tue Aug 21, 2007 3:12 pm

Re: [pymunk] Not working on OSX

Postby maximile » Sun Aug 12, 2012 4:13 pm

That's awesome, thanks so much!
maximile
 
Posts: 157
Joined: Mon Aug 20, 2007 12:53 pm
Location: London, UK

Re: [pymunk] Not working on OSX

Postby viblo » Tue Aug 14, 2012 5:41 am

slembcke wrote:D'oh. I've fixed a number of those where I've done that before. I thought I went through and found all of them. I guess not. I'll take a look at that when I get home from vacation.


I took another look and in the latest version the code looks a bit different from my example. It still defaults to use CGPoints, but its actually possible to override that value by defining CP_USE_CGPOINTS to 0 at compile time.

(didnt see this at first as pymunk trunk is not using the latest version of chipmunk but I have a branch where Im working on upgrading it)
http://www.pymunk.org - A python library built on top of Chipmunk to let you easily get cool 2d physics in your python game/app
viblo
 
Posts: 206
Joined: Tue Aug 21, 2007 3:12 pm


Return to Chipmunk2D Physics

Who is online

Users browsing this forum: Heise IT-Markt [Crawler] and 1 guest

cron