尝试删除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]从bodyColorGreen中销毁MouseJoint
08-13 14:56:18.970 ... A / libc:致命信号11(SIGSEGV)位于0xbf800008(code = 1),线程23033(UpdateThread)

我该如何解决?
谢谢你的时间。

最佳答案

我发现了问题!由于我禁用碰撞并移除物体,所以我遇到了并发问题。我在所有操纵物体添加/删除/碰撞/等方法中使用ReentrantLock修复了这种情况。

关于android - Box2d removeJoint致命信号11(SIGSEGV),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25288735/

10-12 00:38