[bug] Delete a Critter::body

mistigrii33

27-11-2011 21:55:11

Hi,

I'm using the latest Critter release with BuggySwires
I wanted to delete a Critter::Body, and i got the folowing problem : the body is being deleted in PhysX, but not in Ogre ! The Ogre mesh still being visible in the world.
After taking a look at Critter, i found the problem come from the Critter::Node destructor ;
Node::~Node()
{
if (mNodeBehaviour == Enums::SceneNodeDestructorBehaviour_Destroy)
{
destroyNode(mNode);
}mNode = 0;
}

Because the destroyNode is only called when mNodeBehaviour == Enums::SceneNodeDestructorBehaviour_Destroy and because mNodeBehaviour is never initialize anywhere, the destroyNode will never be called.

If you want to reproduce the bug, here is a simple code :

Critter::BodyDescription bodyDesc;
bodyDesc.mMass = 10.0f;
bodyDesc.mGroup = Objects;

NxOgre::BoxDescription boxDesc;
boxDesc.mSize.set(10,10,10);

Critter::Body* b = mRenderSystem->createBody(boxDesc, NxOgre::Vec3(0, 100, 0), "ogrehead.mesh", bodyDesc);
mRenderSystem->destroyBody(b);
// from here you still have the ogrehead in Ogre ! (The SceneNode created by Critter isn't destroyed)


To make the Node destruction works, i initialize this mNodeBehaviour variable in both constructors:
Node::Node(Ogre::SceneManager* scene_mgr, RenderSystem* renderSys)
: mSceneMgr(scene_mgr), mRenderSystem(renderSys)
{
mNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
mNodeBehaviour = Enums::SceneNodeDestructorBehaviour_Destroy;
}

Node::Node(Ogre::SceneManager* scene_mgr, Ogre::SceneNode* parent, RenderSystem* renderSys)
: mSceneMgr(scene_mgr), mRenderSystem(renderSys)
{
mNode = parent->createChildSceneNode();
mNodeBehaviour = Enums::SceneNodeDestructorBehaviour_Destroy;
}

What's the aim of this NodeBehaviour ? Is it for futur release ?

betajaen

28-11-2011 07:06:45

It allows you to pre-create a SceneNode, pass it into NxOgre, and when that body is destroyed, it doesn't delete the SceneNode.

mistigrii33

28-11-2011 08:00:48

It allows you to pre-create a SceneNode, pass it into NxOgre, and when that body is destroyed, it doesn't delete the SceneNode.
Alright, looks pretty evident, i didn't think about it... !
The fix should then be something like that :
Node::Node(Ogre::SceneManager* scene_mgr, RenderSystem* renderSys)
: mSceneMgr(scene_mgr), mRenderSystem(renderSys)
{
mNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
//default ; Critter delete the scene node it made
mNodeBehaviour = Enums::SceneNodeDestructorBehaviour_Destroy;
}
Node::Node(Ogre::SceneManager* scene_mgr, Ogre::SceneNode* parent, RenderSystem* renderSys)
: mSceneMgr(scene_mgr), mRenderSystem(renderSys)
{
mNode = parent->createChildSceneNode();
mNodeBehaviour = Enums::SceneNodeDestructorBehaviour_Inherit;
}

saejox

11-12-2011 20:24:01

I think there is memory leak in destroyBody function.
And it's not simply deleting scenenode.
i tried your modification and deleting node by hand. Memory leaks is not related to it.
Isn't it enough to call destroyBody and destroy scenenode to completely get rid of the body??

mistigrii33

12-12-2011 11:35:47

I think there is memory leak in destroyBody function.
And it's not simply deleting scenenode.
i tried your modification and deleting node by hand. Memory leaks is not related to it.
Isn't it enough to call destroyBody and destroy scenenode to completely get rid of the body??

My modification make Critter to delete the SceneNode it creates instead of deleting it manually.
I saw your other post, and i don't know what this memory leak is related to. Betajean could probably give us more informations..