1

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.

GuilhE
  • 11,591
  • 16
  • 75
  • 116
  • 1
    Probably you're destroying the same joint twice. When you destroy a body all connected joints are destroyed, too. Try to remove the `checkForMouseJoint(body);` line. – cygery Aug 13 '14 at 15:02
  • Yes you're right I don't need that checkForMouseJoint ;) but the problem still persists even without it. – GuilhE Aug 13 '14 at 15:42
  • Can you confirm that you don't destroy the same body twice? – cygery Aug 13 '14 at 15:44
  • I 've found the problem! Well at least I'm not getting this SIGSEGV, so let's hope so... I'll update my question. – GuilhE Aug 13 '14 at 17:23
  • If you've solved your problem please post an answer and accept it. – cygery Aug 13 '14 at 17:36

1 Answers1

2

I've found the problem! Since I was disabling collisions and removing bodies I had a concurrency problem. I fixed this situation using ReentrantLock inside all the methods which manipulate bodies add/delete/collision/etc.... Works great, no more SIGSEGV.

GuilhE
  • 11,591
  • 16
  • 75
  • 116