b2ContactListener and DestroyBody confustion

How does one go about deleting objects that have been identified via b2ContactListener::Add()?

My class thus far looks like this, I've removed things that are irrelevant to this problem to reduce the amount of code:
Code:
class CExitListener : public b2ContactListener
{
public:
   virtual void Add(const b2ContactPoint* point)
   {
      CEntity *e1 = (CEntity*)point->shape1->GetUserData();
      CEntity *e2 = (CEntity*)point->shape2->GetUserData();

      if (!e1 || !e2) return;

      if (/* functions to check that the objects are the ones that we want */)
      {
         if (/* check if the first object is the one we should to delete */)
            ((CEntityTokenRound*)e1)->Collect(); // this function ultimately calls world->DestroyBody(e1's body)
         else // otherwise delete the second
            ((CEntityTokenRound*)e2)->Collect(); // this function ultimately calls world->DestroyBody(e2's body)
      }
   }
};


Stepping through the code reveals that DestroyBody() is being called on the correct bodies, but they are still present in the world afterwards, and permanently so.

How does one delete bodies correctly in this case?
From the manual:
Quote:
It is tempting to implement game logic that alters the physics world inside a contact callback. For example, you may have a collision that applies damage and try to destroy the associated actor and its rigid body. However, Box2D does not allow you to alter the physics world inside a callback because you might destroy objects that Box2D is currently processing, leading to orphaned pointers.

The recommended practice for processing contact points is to buffer all contact points that you care about and process them after the time step.
Ah...

I must have missed that 😛

Thanks Boris.

Original thread: https://box2d.org/forum/viewtopic.php?t=726