I want to change the entity of a node when I push "x".There are the codes.It works .But there are some problem.When I pushed "x" several times,the memory increased 4K.Who tell me why? Thanks.
if (mInputDevice->isKeyDown(KC_X) && mTimeUntilNextToggle <= 0)
{
SceneNode* mRoleNode = mSceneMgr->getSceneNode( "roleNode" );
if(mRoleNode){
String meshNames[]={"ZFGirl.mesh","robot.mesh"};
String entAnimations[]={"walk","Walk"};
//MovableObject* thisObject=mRoleNode->detachObject("roleEnt");
// delete thisObject;
mSceneMgr->removeEntity("roleEnt");
roleNodeIndex=roleNodeIndex ? 0:1;
Entity* roleEnt = mSceneMgr->createEntity( "roleEnt", meshNames[roleNodeIndex] );
roleEnt->setCastShadows( true );
mRoleNode->attachObject( roleEnt );
mRoleAnimState->setEnabled(false);
mRoleAnimState = roleEnt->getAnimationState(entAnimations[roleNodeIndex]);
mRoleAnimState->setEnabled(true);
mTimeUntilNextToggle = 0.5;
mWindow->setDebugText("meshNames["+StringConverter::toString(roleNodeIndex)+"]:"+meshNames[roleNodeIndex]);
}
The problem of memory leak
-
OliverWPZ
- Halfling
- Posts: 53
- Joined: Sun Feb 20, 2005 10:55 am
The problem of memory leak
If you love something...set it free...if back: it`s yours...or:it`s never
- Lucky_Luciano
- Greenskin
- Posts: 136
- Joined: Mon Feb 14, 2005 9:25 pm
- Location: Belgium
I'm new to Ogre but I think you should explicitely destroy a node instead of just removing the entity.
If your node is called "MyNode", use this:
and add a new node containing the new entity.
Perhaps that helps?
If your node is called "MyNode", use this:
Code: Select all
mSceneManager->getRootSceneNode()->removeAndDestroyChild("MyNode");
Perhaps that helps?