private void CleanupBody()
{
if (this.body == null) return;
if (this.shapes != null)
{
foreach (ShapeInfo info in this.shapes)
info.DestroyFixture(this.body, true);
}
this.body.Collision -= this.body_OnCollision;
this.body.Separation -= this.body_OnSeparation;
this.body.PostSolve -= this.body_PostSolve;
// Manually generate OnSeparation events directy in-place, since
// we won't receive next frames Farseer events anymore
ContactEdge edge = this.body.ContactList;
while (edge != null)
{
if (edge.Contact != null && edge.Contact.IsTouching())
{
Fixture fixtureA = edge.Contact.FixtureA;
Fixture fixtureB = edge.Contact.FixtureB;
if (fixtureA != null && fixtureA.Body != null && fixtureA.Body.UserData == this)
this.eventBuffer.Add(new ColEvent(ColEvent.EventType.Separation, fixtureA, fixtureB, null));
else if (fixtureB != null && fixtureB.Body != null && fixtureB.Body.UserData == this)
this.eventBuffer.Add(new ColEvent(ColEvent.EventType.Separation, fixtureB, fixtureA, null));
}
edge = edge.Next;
}
this.body.Dispose();
this.body = null;
}