I'm having a Fatal signal 11 (SIGSEGV) error when I try to remove a mouseJoint. My code is based on this 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;
}
It crashes randomly and my Log.i() shows that's a problem with destroyJoint:
08-13 14:56:18.465 ...I/[Logger] destroyMouseJoint from bodyColorGreen
08-13 14:56:18.970 ...A/libc﹕ Fatal signal 11 (SIGSEGV) at 0xbf800008 (code=1), thread 23033 (UpdateThread)
How can I solve this?
Thanks for your time.