0

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.

Bill
  • 5,263
  • 6
  • 35
  • 50
weston
  • 54,145
  • 21
  • 145
  • 203

2 Answers2

1

Actually, this is what I've found. Posting code in the comments would look awful, that's why the answer instead.

     //remove the rigidbodies from the dynamics world and delete them
    int i;
    for (i=m_dynamicsWorld->getNumCollisionObjects()-1; i>=0 ;i--)
    {
            btCollisionObject* obj = m_dynamicsWorld->getCollisionObjectArray()[i];
            m_dynamicsWorld->removeCollisionObject( obj );
            delete obj;
    }

So you remove the body from the collision objects.

zeller
  • 4,904
  • 2
  • 22
  • 40
  • Thanks, I gave it a shot, but the `removeRigidBody` calls `removeCollisionObject` anyway (in `btDiscreteDynamicsWorld`), so it didn't make any difference. – weston May 27 '13 at 14:02
  • I've asked someone at our local gamedev forum who uses bullet v281 and he said it's clearly not normal behavior. Though that's as far as I can help, I hope you'll get your answer at the bullet forums. – zeller May 27 '13 at 16:43
  • thanks for your effort, it was a stupid bug, please see my answer for details. – weston May 27 '13 at 17:01
0

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.

weston
  • 54,145
  • 21
  • 145
  • 203