Out of range Exception when removing Rigid Bodies

Mar 9, 2008 at 9:19 PM

I've been playing around with the C# port of Bullet and have run into a problem when trying to remove certain rigid bodies. In the simulation I have a floor, table and cup. You can shoot objects from the camera (currently spheres) as a test. When objects roll over the edge of the floor, and drop more than 20 units I remove them from the simulation. This works great as far as the spheres are concerned, you can shoot them and remove them as much as you want. However, once one of the spheres collides with the cup (which is a compound shape), the next rigid body, either the sphere or the cup, to be removed causes an out of range exception in UnionFind.Find(int i). I've traced it back to SimulationIslandManager.cs and it seems to me like the IslandTag is being set incorrectly, or not changed when the objects are removed. I could be completely wrong though.

Has anyone else run into this problem and/or found a solution to it? I'm at somewhat of a loss at where this error could be occurring so any advice would be appreciated.
Thank you,
Mar 23, 2008 at 4:28 PM
Edited Mar 23, 2008 at 4:31 PM
Well, after a few weeks I think I was able to figure out what was wrong. CompoundCollisionAlgorithm does not call Dispose() for its list of CollisionAlgorithms. Dispose() removes the PersistentManifold from the Dispatchers manifold list. Without removing those, you will be trying to access objects that no longer exist inside the SimulationIslandManager.

To fix this, I made CompoundCollisionAlgorithm implement the IDisposible interface, and added the following code:

public void Dispose()
for (int i = 0; i < _childCollisionAlgorithms.Count; i++)
if(_childCollisionAlgorithms[i] is IDisposable)

I'm not sure if this is the best way to resolve the issue, but it does work.

Mar 29, 2008 at 7:37 PM
Hey Marklar - Thanks for that :o) I hit the same problem a while ago for some demos I did. I'll give your 'fix' a try (don't care if it's "good" or not; I'm just glad you took the time to look into it).

FYI here are some of the demos:

Mar 30, 2008 at 3:10 AM
No problem Bob :)

I checked out your demos, they're very nice! Surprising what you can do in a browser now...

Did you by any chance run into any other bugs with Compound Shapes? I've been trying to get the working properly in my game and keep running into different stumbling blocks. The current problem I have relates to the rotation of Compound shapes as the result of a collision. I posted about it here: http://www.codeplex.com/xnadevru/Thread/View.aspx?ThreadId=24977 . If you have any ideas, I'd love to hear them!

Apr 18, 2008 at 6:57 AM
Marklar - Well I tried the fix, but still no joy :( I also fixed (locally) a bug in RemoveOverlappingPairsContainingProxy where it's looping backwards through a loop but increments the counter when it removes an item:

public void RemoveOverlappingPairsContainingProxy(BroadphaseProxy proxy)
for (int i = _overlappingPairs.Count - 1; i >= 0; i--)
BroadphasePair pair = _overlappingPairsi;
if (pair.ProxyA == proxy ||
pair.ProxyB == proxy)
// i++;

(Commented line is my change). Unfortunately it still blows up :( I can mostly avoid the bug if I keep the World simple (using default CollisionDispatcher, SimpleBroadphase etc) and never remove items from the world, but obviously I don't want to do that.

Maybe we can work together to nail the other bugs? (I'm guessing we might find some comparing the original Bullet code to BulletX; we could also incessantly harass the Xnadevru guys or Erwin until they give in and fix it ;o] ).