cocos2d-objc icon indicating copy to clipboard operation
cocos2d-objc copied to clipboard

CCPhysicsBody: switching body "type" when space is locked may assert unexpectedly

Open LearnCocos2D opened this issue 11 years ago • 1 comments

For example, try to change a static body's type to dynamic in a collision callback or other callback where chipmunk space is locked:

    node.physicsBody.type = CCPhysicsBodyTypeDynamic;
    node.physicsBody.affectedByGravity = YES;

This will assert that "Only dynamic bodies can be affected by gravity.". But hey, I just set this to dynamic, didn't I? Problem being that changing the type is deferred into a post-step block due to the locked space. Hence the body remains static for now, which triggers the assertion.

Glancing over the code I can see there are other combinations where asserts might be triggered unwittingly, or even property setters being ignored altogether (ie changing allowsRotation in the above scenario would be ignored).

LearnCocos2D avatar May 07 '14 11:05 LearnCocos2D

I just probably reported the same / similar problem: http://forum.cocos2d-iphone.org/t/possible-bug-in-physics/13329 Test project here https://dl.dropboxusercontent.com/u/147970342/joints.spritebuilder.zip

jonnyijapan avatar May 08 '14 04:05 jonnyijapan