【发布时间】:2014-08-13 14:23:18
【问题描述】:
我在尝试移除 mouseJoint 时遇到致命信号 11 (SIGSEGV) 错误。我的代码是基于这个AndEngine PhysicsMouseJointExample
//physicWorld onUpdate
@Override
public void onUpdate(float pSecondsElapsed) {
if (removeMouseJoint) {
destroyMouseJoint();
removeMouseJoint = false;
}
for (Body body : elementsToBeDestroyed) {
destroyBody(body, elementsMap.remove(body).getKey());
checkForMouseJoint(body);
}
elementsToBeDestroyed.clear();
}
private void destroyBody(final Body body, final IShape mask) {
if (physicsWorld != null) {
physicsWorld.unregisterPhysicsConnector(physicsWorld.getPhysicsConnectorManager().findPhysicsConnectorByShape(mask));
physicsWorld.destroyBody(body);
}
}
private void checkForMouseJoint(Body body) {
if (mouseJointActive != null && mouseJointActive.getBodyB() != null && mouseJointActive.getBodyB().equals(body)) {
destroyMouseJoint();
}
}
private void destroyMouseJoint() {
if (mouseJointActive != null && mouseJointActive.getBodyB() != null) {
Log.i(C.TAG, "destroyMouseJoint from " + mouseJointActive.getBodyB().getUserData());
physicsWorld.destroyJoint(mouseJointActive);
}
mouseJointActive = null;
}
@Override
public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent) {
switch (pSceneTouchEvent.getAction()) {
case TouchEvent.ACTION_UP:
if (sceneTouchId == pSceneTouchEvent.getPointerID()) {
sceneTouchId = -1;
// destroyMouseJoint();
removeMouseJoint = true;
}
return true;
}
…
return false;
}
它随机崩溃,我的 Log.i() 显示 destroyJoint 存在问题:
08-13 14:56:18.465 ...I/[Logger] destroyMouseJoint from bodyColorGreen08-13 14:56:18.970 ...A/libc: 致命信号 11 (SIGSEGV) at 0xbf800008 (code=1), thread 23033 (UpdateThread)
我该如何解决这个问题?
感谢您的宝贵时间。
【问题讨论】:
-
你可能会两次破坏同一个关节。当你摧毁一个身体时,所有连接的关节也会被摧毁。尝试删除
checkForMouseJoint(body);行。 -
是的,你是对的,我不需要那个 checkForMouseJoint ;) 但即使没有它,问题仍然存在。
-
你能确认你不会两次摧毁同一个身体吗?
-
我找到了问题!好吧,至少我没有收到这个 SIGSEGV,所以希望如此......我会更新我的问题。
-
如果您的问题已解决,请发布答案并接受。
标签: android box2d andengine segmentation-fault jbox2d