FP3 World.Remove(BreakableBody) issue after breaking the body

May 4, 2010 at 4:12 PM

I think I've found a bug in the World.Remove(BreakableBody) method, or I'm missing something.

When it's called, it iterates for each part removing their bodies from the World:

//Remove all the parts of the breakable body.
for (int i = 0; i < body.Parts.Count; i++)

The problem is that the parts have no body associated after the breakable body has been broken (after it's broken, it calls the destroyfixture method for each part), so I get a null reference when called the remove method.

May 5, 2010 at 9:22 AM
Edited May 5, 2010 at 9:44 AM
I'm checking the code, and I think that in the BreakableBody, the bodies for the broken parts (which are created after the the main body is broken) should be stored in a list. Then in the World.Remove(BreakableBody), it should check if the BreakableBody is broken, and then remove the bodies from this list instead of the bodies associated to each part. I can change the code and submit it as a patch (I should ask to join the project I guess) or put it in pastebin this afternoon.

Edit: Also I'm taking a look to Erin Catto's BreakableBody's code, and I see that additional code for calculating better the resulting the part's velocities should be added. Currently when a BreakableBody breaks (that's a lot of "break" words), it looks a little unrealistic as all the pieces move lineary to the same direction, instead of "radiate" from the break point. I'm not sure if I'm making me clear, as my english quite sucks... I'll try to modify the break code and show the differences in a video later.
May 5, 2010 at 3:06 PM
Edited May 5, 2010 at 3:09 PM

Ok, I've modified the BreakableBody class, now the pieces move towards the same main body's direction. I also modified the PostSolve function for cases when only one contact point is in the manifold (for example a circle).

I additionally added a Vector2 _breakPoint, where the place where the body has been broken, I did it because I need some kind of explosive effect when broken.

Here it is: PasteBin (Main changes are in line 125)

Lines 40, 57, 62 and 64 can be removed if you are not interested on recording the breakpoint.

Now, for the World.Remove(BreakableBody)...