assertion when destroying bodise

Mar 28, 2010 at 8:00 PM

In my code, to completely clear out the world of existing bodies, I run this loop:


                for (Body body = world.GetBodyList(); body != null; body = body.GetNext())
                {
                    world.DestroyBody(body);
                }


for (Body body = world.GetBodyList(); body != null; body = body.GetNext())

{

    world.DestroyBody(body);

}

 


However, this will trigger the assertion "Debug.Assert(_bodyCount > 0);" in World.DestroyBody(Body).

Any suggestion as to how this can happen?

 

- John

Coordinator
Mar 29, 2010 at 1:05 AM

The assert is valid and is indicating that something went wrong.

I was unable to repro the problem with one of my test worlds.

Can you point me to a reduced repro app that shows the problem?  I should be able to debug it if I can reproduce the problem.

Are you doing any custom destruction handling or modifying _bodyList manually anywhere in your code?  The CreateBody/DestroyBody are the only points where _bodyCount is modified in the engine so it should always be accurate unless something else steps in to modify the list or the count directly.

Coordinator
Mar 30, 2010 at 3:54 PM

It would be helpful if you could attach the repro nfurtwangler mentioned, but as a side note:  If you're trying to clean up the world after a level to reuse it for the next level, you could go about it a different way.  It's probably simpler/faster just to make a new world and let the GC take care of the old one.

Apr 8, 2010 at 2:16 PM

Hi - sorry about not getting back to you. I forgot to check the "send me emails with replies" button.

My solution was to do as bfurtwrangler suggested - create a new world for the new level.

I am not sure I can make a reduced version...I will try when I have a little more time.