我们有两个固定装置 vector (都是一个物体)
//Create and add fixtures to vector1 and vector2
b2PolygonShape shape1;
shape1.SetAsEdge(from1,to1);
vector1.push_back( body1->CreateFixture(&shape1,0) );
b2PolygonShape shape2;
shape2.SetAsEdge(from2,to2);
vector2.push_back( body2->CreateFixture(&shape2,0) );
当 case event1 时,我们销毁 vector1 中的第一个 fixture。
body1->DestroyFixture( vector1[0] ); //destroy first fixture1
vector1.erase( vector1.begin() ); //remove from vector1
当 case event2 时,我们销毁 vector2 中的第一个 fixture。
body2->DestroyFixture( vector2[0] ); //destroy first fixture2
vector2.erase( vector2.begin() ); //remove from vector2
问题: 有时,当我们 DestroyFixture(...) 时,我们得到“Assertion failed: (fixture->m_body == this)”
我检查过,我知道 vector1 可以有一些 fixture2,或者 vector2 有 fixture1。为什么可以呢? 我仅将 fixture1 添加到 vector1,将 fixture2 仅添加到 vector2。
最佳答案
如果您在碰撞回调函数中这样做,请不要这样做。 Box2D 禁止在碰撞事件中移除物体/固定装置。相反,稍后标记主体以进行碰撞后处理,例如在下一个更新方法调用中。
关于iphone - 断言失败 : (fixture->m_body == this),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9853993/