This project has moved and is read-only. For the latest updates, please go here.

OnSeparation after disposing a body

Topics: Developer Forum, Project Management Forum, User Forum
Apr 18, 2012 at 7:46 PM
Edited Apr 18, 2012 at 8:16 PM

Hello everyone,

I have some sensors that keep a list of objects with OnCollision and OnSeparation. However, when one body is disposed, the OnSeparation event is not raised in the sensor. Is that reasonable? I thought after disposing, OnSeparations would be invoked since there is indeed a separation.

Could it be possible to modify the Dispose method in Body so OnSeparation can be raised for those touching objects in the ContactList?



public class Body
#region otherstuff

public void Dispose() { if (!IsDisposed) { ContactEdge contactEdge = ContactList; Contact contact; while (contactEdge != null && (contact = contactEdge.Contact) != null) { //Report the separation to both participants: if (contact.FixtureA != null && contact.FixtureA.OnSeparation != null) contact.FixtureA.OnSeparation(contact.FixtureA, contact.FixtureB); //Reverse the order of the reported fixtures. The first fixture is always the one that the //user subscribed to. if (contact.FixtureB != null && contact.FixtureB.OnSeparation != null) contact.FixtureB.OnSeparation(contact.FixtureB, contact.FixtureA); contactEdge = contactEdge.Next; } World.RemoveBody(this); IsDisposed = true; GC.SuppressFinalize(this); } }



I suppose that's okay as long as the Dispose method is not executed from World.Step(...). Can you agree with me?