Page 1 of 1
[pymunk] Not working on OSX
Posted: Tue Aug 07, 2012 5:14 pm
by maximile
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.
Re: [pymunk] Not working on OSX
Posted: Wed Aug 08, 2012 12:08 am
by aisman
Have you ask the pymunk developers too?
Maybe they are the first choice for solving your problem.
Re: [pymunk] Not working on OSX
Posted: Wed Aug 08, 2012 8:56 am
by maximile
aisman wrote:Have you ask the pymunk developers too?
Thanks, I e-malled viblo as well.
Re: [pymunk] Not working on OSX
Posted: Wed Aug 08, 2012 10:13 am
by viblo
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.
Re: [pymunk] Not working on OSX
Posted: Wed Aug 08, 2012 4:03 pm
by maximile
Thanks viblo, I'm glad you could reproduce the error. I'll keep playing too and let you know if I find anything.
Re: [pymunk] Not working on OSX
Posted: Fri Aug 10, 2012 9:48 am
by viblo
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?
Re: [pymunk] Not working on OSX
Posted: Fri Aug 10, 2012 12:44 pm
by slembcke
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.
Re: [pymunk] Not working on OSX
Posted: Sat Aug 11, 2012 5:14 am
by viblo
Ok, great
maximile: Ive checked in a fix for this problem in pymunk svn trunk.
Re: [pymunk] Not working on OSX
Posted: Sun Aug 12, 2012 4:13 pm
by maximile
That's awesome, thanks so much!
Re: [pymunk] Not working on OSX
Posted: Tue Aug 14, 2012 5:41 am
by viblo
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)