我正在写一个游戏,我必须在碰撞时移除一个带有身体的矩形砖。错误发生在 * _ physicsWorld.destroyBody(b); *
这是我的代码片段和logcat输出(logcat说 libc 中有错误):
代码:
public void destroyBrick(IShape s, Body b, int i){
PhysicsConnector facePhysicsConnector = _physicsWorld.getPhysicsConnectorManager().findPhysicsConnectorByShape(s);
_physicsWorld.unregisterPhysicsConnector(facePhysicsConnector);
_scene.unregisterTouchArea(s);
_scene.detachChild(s);
_physicsWorld.destroyBody(b);
System.gc();
}
logcat的:
***08-19 12:58:17.491: A/libc(29832): /home/denbi/src/android/AndEngineExtensions/AndEnginePhysicsBox2DExtensionNew/jni/Box2D/Dynamics/b2World.cpp:134: void b2World::DestroyBody(b2Body*): assertion "IsLocked() == false" failed
08-19 12:58:17.501: A/libc(29832): Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1), thread 29852 (UpdateThread)***
请尽快帮助我。
感谢
答案 0 :(得分:3)
在执行b2World::Step
期间无法删除正文。您必须存储要删除的实体列表,并在Step退出时实际删除它们。
示例(C ++):
//in contact handling:
m_bodiesToRemove.push_back(my_body);
//after Step:
for (b2Body *b : m_bodiesToRemove):
m_world->DestroyBody(b);