Box2D colission between static/dynamic bodies causing an assert
I'm using BOX2D for the first time on iPhone. On the whole it's been pretty good, but I keep repeatedly getting an assert on a line in ContactManager whenever I create a scene featuring both static and dynamic bodies. The exact line is...
b2Assert(bodyA->m_type == b2_dynamicBody || bodyB->m_type == b2_dynamicBody);
Which is in void b2ContactManager::Collide(). This seems to suggest that it's asserting when two objects collide, one of which isn't dynamic... which makes no sense at all开发者_运维技巧. Of course dynamic bodies are supposed to collide with static ones!
It doesn't assert on this line until I create static objects strangely. I have tons of dynamic boxes moving arond the screen. As soon as I introduce one static one, I get a crash here.
Can anyone help me out? This seems like one of those 'Really obvious' type of problems!
Do you move your static bodies after they're created? (Beyond just setting their initial position?): I had issues with static bodies being moved causing strange issues (not asserts, but odd collision behaviour) and then discovered that Box differentiates between static and kinematic bodies (b2_staticBody and b2_kinematicBody, respectively)
Kinematic bodies have infinite mass and don't respond to forces (as per static) but it is stated that they can manually be moved (static bodies can be moved manually too, but they're not expected to be moved whilst responding to collisions etc. and can cause weird behaviour)
Probably isn't your issue (since you imply it's immediately after static bodies are made) but might be worth checking I suppose + If you're relatively new to Box you may have already seen this in the manual. This only came as news to me because I started using Box ages ago (to suddenly have the concept of kinematic appear)
The problem is that two non-dynamic bodies are colliding. It's incorrect because kinematic and static bodies should not collide the each other. Such collision are ignored by box2d. But it is happening in your situation. Please provide some phys initialization code for more detailed answer why it's happening.
精彩评论