[solved] Problem deleting a body on Release Mode

hoffhoff

14-12-2008 16:35:31

Hello,
I am creating a shooting game, and then I want my "bullet" object to be destroyed after 5 seconds since it was shot.

My "Bullet" class agregates an OgreNewt::Body* (mpBody), an Ogre::Entity* (mpEntity) and an Ogre::SceneNode* (mpSceneNode) basically.

In the destructor, I am doing this:



if (mpBody)
{
delete mpBody;
mpBody = NULL;
}

if (mpEntity)
{
delete mpEntity;
mpEntity = NULL;
}

if (mpSceneNode)
{
delete mpSceneNode;
mpSceneNode = NULL;
}




I am calling the "delete bullet;" in the "frameStarted" event of my Event class, which is derivated from "Ogre::FrameListener".


My code works fine in the Debug mode, but crashes when compiled in the Release mode.

Is there something wrong with the steps I am doing? I mean... is it fine to delete the objects in the "frameStarted" event?

Also, is there something I should do before trying to delete a body?

Thanks!

hoffhoff

14-12-2008 16:47:13

Oh, that´s ok, I found out my problem on Ogre´s forum. I should not delete the ogre´s entities directly, but do this:



if (mpEntity != NULL)
{
mpSceneManager->destroyEntity(mpEntity);
mpEntity = NULL;
}


if (mpSceneNode != NULL)
{
mpSceneManager->destroySceneNode(mpSceneNode);
mpSceneNode = NULL;
}


Sorry :oops: