Hi, i'm making a simple top down shooter game which have bullets entity, my problem is the bullet entity dtor is not called when i call the delete operator.
here's some of my code :
CBullet.hpp
namespace CEntity
{
class CBullet
{
private:
b2Body* m_Body;
public:
CBullet(b2World* world, const b2Vec2& normal, const b2Vec2& pos, float rot);
~CBullet();
};
}
CBullet.cpp
CEntity::CBullet::CBullet(b2World* world, const b2Vec2& normal, const b2Vec2& pos, float rot)
{
//
fixDef.filter.categoryBits = CEntity::BULLET;
m_Body->CreateFixture(&fixDef);
//
m_Body->SetUserData(this);
}
CEntity::CBullet::~CBullet()
{
m_Body->GetWorld()->DestroyBody(m_Body);
}
Cgun (responsible for creating the bullet with new operator)
void CEntity::CGun::shoot(const b2Vec2& normal, const b2Vec2& pos, float rot)
{
//
new CEntity::CBullet(m_World, normal, pos, rot);
//
}
ContactListener (where the deletion should occur)
void EndContact(b2Contact* contact)
{
b2Fixture* fixA = contact->GetFixtureA();
b2Fixture* fixB = contact->GetFixtureB();
if (fixA->GetFilterData().categoryBits == CEntity::BULLET)
{
delete static_cast<CEntity::CBullet*>(fixA->GetUserData());
}
if (fixB->GetFilterData().categoryBits == CEntity::BULLET)
{
delete static_cast<CEntity::CBullet*>(fixB->GetUserData());;
}
}
that's all, im using box2d by the way, any help would be apreciated :)
Surya
PS: Sorry for my bad english