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:
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?
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)
}
}
};
{
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?