Removing Body and Fixtures

Topics: Developer Forum
Feb 28, 2013 at 3:20 AM
Hi all. Having a little trouble removing bodies in my test game.

I have created the world, and spawned a few bodies for testing. Everything works, but when i try to delete the bodies i get a NullReferenceException in FarseerPhysics.Dynamics.Fixture (line 239 if it helps).

I'm simply using World.RemoveBody( someBody ) to remove my bodies, is there something else i should be doing to remove the fixtures too?

Thanks.
Mar 1, 2013 at 3:43 PM
World.RemoveBody should do it. I use it quite a bit without issue. I've seen the NullReferenceException in Fixture before but, if I recall correctly, it happened when I tried to use the body after I had removed it from the world. Perhaps look into that to see if that is your issue (i.e. make sure you're not trying to do something with the body after removing it).

Also, if you're removing all of the bodies, you could use World.Clear() instead to see if that works better for you.

Good luck,
Mike.
Mar 4, 2013 at 5:01 PM
Ah you're right, i was drawing the object after it had been removed. Cheers!