Search code examples
c++bulletphysics

Removing a rigid body, but still getting collisions for it


What is the correct way to remove a rigid body, I am doing just this to remove it:

void removeRigidBody(btDynamicsWorld* pDynamicsWorld, btRigidBody* rb)
{
   pDynamicsWorld->removeRigidBody(rb);
   delete rb->getMotionState();
   delete rb;
}

However, the object still appears in pDynamicsWorld->getCollisionObjectArray() after I do a pDynamicsWorld->stepSimulation

Strangely enough this does not happen on ARM, just x86.


Solution

  • This was, like most bugs just a stupid mistake. Sorry to those who took time to read it.

    The error was actually in some java that called the removeRigidBody by jni.

    if (body.id > 0) {
    

    The id is actually an int cast of the btRigidBody address, so of course any != 0 integer could be a valid address. On the x86, the addresses happened to be < 0 which on the other device happened to be > 0.