Nov 8, 2010 at 5:54 PM
Edited Nov 8, 2010 at 7:50 PM
Idea is that when an object lands on the player and the force is greater than X, character loses health. Works fine in terms of calculating the force of impact, but if I try to remove the Body from the World, I get a crash:
private void PostSolve(ContactConstraint contactConstraint)
float maxImpulse = 0;
for (int i = 0; i < contactConstraint.Manifold.PointCount; ++i)
maxImpulse = Math.Max(maxImpulse, contactConstraint.Manifold.Points[i].NormalImpulse);
if (maxImpulse >= deathOnImpactSize)
I'm assuming it's because somehow I'm trying to remove a Body that's been removed, even though technically I've just removed it and it no longer exists? So PostSolve is being called multiple times?
If I call_world.RemoveBody(_fixture.Body);
at level startup (ie just once) it works fine. How can I limit the call to remove that fixture just once?
I've run some more tests, and confirmed that there's no crash if I call RemoveBody multiple times outside of PostSolve (by holding down a button, for example).
EDIT also, it looks like it's crashing out here, in World.cs
Which makes sense. What's locked, here? And why is it locked?