Two issues with compound shapes

Post Reply
tp
Posts: 13
Joined: Sat Dec 09, 2006 8:10 am

Two issues with compound shapes

Post by tp »

I stumbled across two issues, the other which I couldn't work around. I'm using 2.73 and VS2005.

I have a component based engine that works by first creating an instance of btRigidBody in one object, along with a compound shape to house the actual collision shapes relative to the origin of the object. The btCollisionShape instances live in other objects, which are added later (relatively speaking).

If I create a compound shape and a rigid body with the empty compound shape, Bullet goes nuts after I add more child shapes later. I refactored my code to delay the creation of both the original compound and the rigid body until one child shape is available, and that solves the problem and the simulation is stable again. The fact that an empty compound shape is not viable on its own is probably either a bug, or something that is probably not a very uncommon occurrence in a similar situation when loading shapes from resource files and should be documented and/or asserted.

Another problem came up when I tried to manipulate the positions of the child shapes in the compound shape using updateChildTransform. The function crashes on the line:

Code: Select all

m_dynamicAabbTree->update(m_children[childIndex].m_node,bounds);
This is because m_children[childIndex].m_node has an invalid value. This, in turn, is caused (I suspect) by the fact that btCompoundShape::addChildShape contains the following after the child has already been pushed to the list:

Code: Select all

child.m_node = m_dynamicAabbTree->insert(bounds,(void*)index);
If I move the push_back to the end of the method, the m_node pointers seem fine, but btCompoundLeafCallback::ProcessChildShape starts crashing due to the fact that childShape is a stray pointer on the following line:

Code: Select all

childShape->getAabb(newChildWorldTrans,aabbMin0,aabbMax0);
Following back, this is called from btCompoundLeafCallback::Process, where leaf->dataAsInt is -1. This is obviously an invalid index, but that's as far as I can get without knowing the library internals better.

It would be great if someone who better understands the internals could make a fix to this that I could apply without having to wait for the next release. Also an explanation about what's going on with the nodes would possibly help me to track down the problem myself.

Thanks in advance for any advice.
tp
Posts: 13
Joined: Sat Dec 09, 2006 8:10 am

Re: Two issues with compound shapes

Post by tp »

The second crash went away when I realised the index needs not be decremented when the push_back is moved. I.e. replace:

Code: Select all

int index = m_children.size()-1;
with

Code: Select all

int index = m_children.size();
I'd still like to get confirmation that doing this is ok.
tp
Posts: 13
Joined: Sat Dec 09, 2006 8:10 am

Re: Two issues with compound shapes

Post by tp »

Any advice from someone who knows the internals better on these two issues?

My primary problem at the moment is the first issue, i.e. adding shapes to empty compounds causing incorrect behaviour. Based on the debug drawer output, there are some internal contact penetrations that don't resolve that keep adding impulses to the object.

I've had no troubles with the fix I made to the second issue, I'd be happy to hear it was accepted into the development version so I don't have to keep fixing it myself in upcoming versions.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Two issues with compound shapes

Post by Erwin Coumans »

When you change a collision shape, such as adding children to a btCompoundShape or changing the local scaling, you need to update the btRigidBody inertia tensor.

After changing the collision shape, use:

Code: Select all

//given a btRigidBody* body with its mass (static -> mass = 0)
btVector3 localInertia;
compoundShape->calculateLocalInertia(mass,inertia);

body->setMassProps(mass,inertia);
body->updateInertiaTensor();
Hope this helps,
Erwin
tp
Posts: 13
Joined: Sat Dec 09, 2006 8:10 am

Re: Two issues with compound shapes

Post by tp »

Erwin Coumans wrote:When you change a collision shape, such as adding children to a btCompoundShape or changing the local scaling, you need to update the btRigidBody inertia tensor.
I'm doing this, along with recalculateLocalAabb on the compound shape.

The behaviour I'm seeing is definitely not tied to inertia, as there are forces that get generated and the debug drawer indicates internal contacts (specifically, DBG_DrawContactPoints is drawing lines). I'm also adding more than one shape to the compound, and this problem does not manifest after the first shape, if the first shape is added when the rigid body is created, so the inertia calculations I'm doing are probably correct.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Two issues with compound shapes

Post by Erwin Coumans »

There were 2 bugs in the btCompoundShape, they are now fixed.
  • When adding/removing child shapes, some internal caches needed to be invalidated
  • Without child shapes, the aabbMin = INF and aabbMax = -INF. Such 'inside-out' AABB is invalid and it causes issues in the broadphase (the object will collide with itself)
Without the latest fixes, one workaround is to remove and add the rigid body from the dynamics world, after the changes.

Can you update to latest SVN revision?

Thanks a lot for the report,
Erwin
JohnnyM
Posts: 15
Joined: Tue Dec 23, 2008 11:51 pm

Re: Two issues with compound shapes

Post by JohnnyM »

How can I get these updates? I am having problems with the compound object aswell.
Post Reply