Page 1 of 1
Removing a rigid body
Posted: Mon Nov 13, 2006 6:43 pm
by nomad
What is the correct way to remove a rigid body from btDynamicsWorld? Unless I am missing something simple, there is nothing like a btDynamicsWorld::removeRigidBody() function.
Just deleting the rigid body causes btDynamicsWorld::stepSimulation() to crash.
Thanks.
Re: Removing a rigid body
Posted: Mon Nov 13, 2006 6:58 pm
by Erwin Coumans
nomad wrote:What is the correct way to remove a rigid body from btDynamicsWorld? Unless I am missing something simple, there is nothing like a btDynamicsWorld::removeRigidBody() function.
Just deleting the rigid body causes btDynamicsWorld::stepSimulation() to crash.
Thanks.
Pressing 'END' key should remove objects in most Bullet demos. Which version of Bullet are you using? There should be
virtual void removeRigidBody(btRigidBody* body);
Please check out the BasicDemo for the right order to remove things:
Code: Select all
void BasicDemo::exitPhysics()
{
//cleanup in the reverse order of creation/initialization
//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;
}
//delete collision shapes
for (unsigned int j=0;j<m_collisionShapes.size();j++)
{
btCollisionShape* shape = m_collisionShapes[j];
delete shape;
}
//delete dynamics world
delete m_dynamicsWorld;
//delete collision algorithms creation functions
delete m_sphereSphereCF;
delete m_sphereBoxCF;
delete m_boxSphereCF;
//delete solver
delete m_solver;
//delete broadphase
delete m_overlappingPairCache;
//delete dispatcher
delete m_dispatcher;
}
There might be functionaly missing for objects with constraints involved, I have to check that out. Notice that collision shapes can be re-used among several rigidbodies.
This should be really in the Bullet User Manual.
Thanks for the feedback,
Erwin
Posted: Mon Nov 13, 2006 7:29 pm
by nomad
Thanks for that ... removeRigidBody() isn't referenced in the docs, and I didn't think to search all the source for removeRigidBody

Re: Removing a rigid body
Posted: Sat Nov 18, 2006 4:38 pm
by nomad
Erwin Coumans wrote:
Please check out the BasicDemo for the right order to remove things:
What about the btDefaultMotionState pointer (created in DemoApplication::localCreateRigidBody() )?
Shouldn't this also be explicitly deleted?
Thanks.
Re: Removing a rigid body
Posted: Sat Nov 18, 2006 4:53 pm
by Erwin Coumans
nomad wrote:Erwin Coumans wrote:
Please check out the BasicDemo for the right order to remove things:
What about the btDefaultMotionState pointer (created in DemoApplication::localCreateRigidBody() )?
Shouldn't this also be explicitly deleted?
Thanks.
Indeed, that needs to be explicitly deleted indeed. If you already have a graphics object, its destructor would be a good place to delete the motionstate. In the simple Bullet demos, there are no graphics 'objects'.
I'll add some cleanup code in DemoApplication.
Thanks for the feedback,
Erwin