slembcke/Chipmunk-Physics — Issue #12: Chipmunk 6.0.3 incompatible with SpaceManager under Mac (CP_USE_CGPOINTS not defined)
Author: LearnCocos2D
Created: 2012-01-21 15:35:33+00:00
State: open

In 6.0.2 in chipmunk_types.h the CP_USE_POINTS macro was based on these conditionals:

#if (defined TARGET_OS_IPHONE) && (!defined CP_USE_CGPOINTS)
#define CP_USE_CGPOINTS
#endif

With 6.0.3 this has changed to this:

#if (TARGET_OS_IPHONE == 1) && (!defined CP_USE_CGPOINTS)
#define CP_USE_CGPOINTS 1
#endif

For some reason this causes CP_USE_CGPOINTS not to be defined when you're building for the Mac, and that in turn causes incompatibilities with Chipmunk Spacemanager and possibly other code as well, with error messages like these:
error: sending 'cpVect' (aka 'struct cpVect') to parameter of incompatible type 'CGPoint' (aka 'struct CGPoint')
Conflicting parameter types in implementation of 'setPosition:': 'CGPoint' (aka 'struct CGPoint') vs 'cpVect' (aka 'struct cpVect')

My proposed fix is to simply include TARGET_OS_MAC as well, since Mac OS also defines CGPoint:

#if (TARGET_OS_IPHONE == 1) || (TARGET_OS_MAC == 1) && (!defined CP_USE_CGPOINTS)
#define CP_USE_CGPOINTS 1
#endif

This fix builds successfully for Mac, iOS Device and Simulator and is compatible with SpaceManager in all cases. Tested with Kobold2D.