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.
Removing a rigid body
-
- Site Admin
- Posts: 4221
- Joined: Sun Jun 26, 2005 6:43 pm
- Location: California, USA
Re: Removing a rigid body
Pressing 'END' key should remove objects in most Bullet demos. Which version of Bullet are you using? There should benomad 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.
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;
}
This should be really in the Bullet User Manual.
Thanks for the feedback,
Erwin
-
- Posts: 32
- Joined: Sun Jun 18, 2006 10:22 pm
-
- Posts: 32
- Joined: Sun Jun 18, 2006 10:22 pm
Re: Removing a rigid body
What about the btDefaultMotionState pointer (created in DemoApplication::localCreateRigidBody() )?Erwin Coumans wrote:
Please check out the BasicDemo for the right order to remove things:
Shouldn't this also be explicitly deleted?
Thanks.
-
- Site Admin
- Posts: 4221
- Joined: Sun Jun 26, 2005 6:43 pm
- Location: California, USA
Re: Removing a rigid body
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'.nomad wrote:What about the btDefaultMotionState pointer (created in DemoApplication::localCreateRigidBody() )?Erwin Coumans wrote:
Please check out the BasicDemo for the right order to remove things:
Shouldn't this also be explicitly deleted?
Thanks.
I'll add some cleanup code in DemoApplication.
Thanks for the feedback,
Erwin