[SOLVED] GDX Bullet - Referencing a rigid body stops all motion

This is probably simple to fix, but I’ve noticed a few times and I wanted to start a topic about it. I understand LibGDX uses bullet through the JNI, and this could simply be some sort of reference issue, but I’m curious how I would fix it.

for(Player node : world.getConnectedPlayers().values()){
    final btRigidBody body = node.getBody();
    if(body.checkCollideWith(getBody()))
        collidingPlayers.add(node);
}

Specifically in this case, the players are contacting a body with a no collision response flag ([icode]btCollisionObject.CollisionFlags.CF_NO_CONTACT_RESPONSE[/icode]). The code above is to check if the players are colliding with the body, the problem is the colliding body ([icode]node.getBody()[/icode]) stops moving immediately and wont respond.

If anyone’s able to help I’d love to reward some fake internet points :wink:

EDIT: Some more notes, [icode]body.activate()[/icode] and [icode]getBody().activate[/icode] does nothing…

HAH! Solved it.

Turns out the thread that listens to events was creating the players and their rigid bodies on the server itself, when a player connected it put it onto the wrong thread.

Later when the main game thread updates the server, it tries to access the body and in doing so the JNI glitches out and creates two instances, one to be broadcasted to clients and the other used in my [icode]checkCollideWith[/icode] method

Sorry for the headaches for anyone who read this

world.getDynamicsWorld().contactPairTest(body, getPhysNode().getBody(), new ContactResultCallback(){
    @Override
    public float addSingleResult(btManifoldPoint cp, btCollisionObjectWrapper colObj0Wrap, int partId0, int index0, btCollisionObjectWrapper colObj1Wrap, int partId1, int index1) {
        System.out.println("Collided");
        return 0;
    }
});

Actually, I tested my method again and I found it always returned “true”, I believe its because I have multiple dynamics worlds in the same thread. The method above is a simple way to test collision of two objects in the context of a specific dynamics world, and it works perfectly for me!