I have classes like this:
class CWorldObject
{
public:
CWorldObject() :
m_body(nullptr),
m_collisionShape(nullptr)
{
m_rootNode = EING_ST.graphic().scene()->CreateChild();
}
~CWorldObject()
{
m_rootNode->UnsubscribeFromAllEvents();
m_rootNode->Remove();
}
Urho3D::Node *rootNode()
{
return m_rootNode;
}
Urho3D::RigidBody *body()
{
if(!m_body)
{
m_body = rootNode()->CreateComponent<Urho3D::RigidBody>();
m_body->SetCollisionEventMode(Urho3D::COLLISION_ALWAYS);
}
return m_body;
}
Urho3D::CollisionShape *collisionShape()
{
if(!m_collisionShape)
{
m_collisionShape = rootNode()->CreateComponent<Urho3D::CollisionShape>();
}
return m_collisionShape;
}
private:
Urho3D::Node *m_rootNode;
Urho3D::RigidBody *m_body;
Urho3D::CollisionShape *m_collisionShape;
};
I do not understand how to free memory when removing such classes.
I understand that it is necessary to delete each created object. But when I try to do it - the application crashes. Moreover, it abnormally terminates even with such a destructor as it is now.