issue/bug when removing/adding rigid bodies to world

Post Reply
Posts: 170
Joined: Fri Apr 18, 2008 2:20 pm

issue/bug when removing/adding rigid bodies to world

Post by gjaegy » Thu Aug 02, 2012 2:31 pm


I came across an issue, and it took me quite some time to figure out what was going on.

Basically, in our application, kinematic rigid bodies are sometimes removed (not destroyed) from the world, and added again later on.

I agree this is not a typical usage, but this is what we do.

The problem arise in the following case:
  • rigid body use motion state
  • move 3D object (implicitly rigid body because of the motion state usage) to P1
  • after some time, remove kinematic rigid body from world
  • 3D object moves meantime to P2
  • re-add rigid body to world
  • add a constraint (btUniversalConstraint for instance)
The issue is, the constraint is not set correctly relatively to the rigid body. Reason for that, is that the btUniversalConstraint constructor compute "m_frameInA" and "m_frameInB" using "btRigidBody::getCenterOfMassTransform()", which returns "btCollisionObject::m_worldTransform".

Code: Select all

// now get constraint frame in local coordinate systems
m_frameInA = rbA.getCenterOfMassTransform().inverse() * frameInW;
m_frameInB = rbB.getCenterOfMassTransform().inverse() * frameInW;

Code: Select all

const btTransform&  getCenterOfMassTransform() const { 
	return m_worldTransform; 
And yet, "btCollisionObject::m_worldTransform" hasn't been updated since the rigid body has been removed from the world, it still points to P1 - where the real current location is P2.

I managed to fix this, by manually synchronizing the "m_worldTransform" with my motion state when adding the rigid body to the world.

However, I wonder if this isn't a bug/flaw of Bullet ? Shouldn't "btDiscreteDynamicsWorld::addRigidBody" ensure "btCollisionObject::m_worldTransform" is up-to-date with the optional motion state ?

Thanks for any input !

Post Reply