Node/Mesh replace, freeing memory? Some help, please ;)

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Gogolian
Posts: 32
Joined: Sat May 17, 2008 10:49 pm

Node/Mesh replace, freeing memory? Some help, please ;)

Post by Gogolian »

Hey, quick question.

How to replace a mesh/node for another mesh/node, freeing memory (so the old triangles will be thrown out)?

i got globbaly:

Code: Select all

IAnimatedMesh* mesh;
ISceneManager* smgr;
IAnimatedMeshSceneNode* node = 0;
and a func:

Code: Select all

void mapChange(int mapnum)
{
 /*switch(mapnum){
  case 1:{mesh->drop(); mesh = smgr->getMesh("room01.obj"); break;}
  case 2:{mesh->drop(); mesh = smgr->getMesh("terrain06.obj"); break;}
  case 3:{mesh->drop(); mesh = smgr->getMesh("terrain01.obj"); break;}

 }*/
 //smgr->getMeshCache()->removeMesh(mesh);
 mesh->drop();
//node->drop();
 if(mapnum == 1){mesh = smgr->getMesh("room01.obj");node = smgr->addAnimatedMeshSceneNode(mesh);}
 if(mapnum == 2){mesh = smgr->getMesh("terrain06.obj");node = smgr->addAnimatedMeshSceneNode(mesh);}
 if(mapnum == 3){mesh = smgr->getMesh("terrain01.obj");node = smgr->addAnimatedMeshSceneNode(mesh);}
}
I tried few things but seems that memory isn't freed.
I think (i am not sure i'm right) that memory of a node isn't deleted, but when i add node->drop() the program is crashing

It is releted to terrain. I want swiching the terrain to be fast and simple, and to load a mesh on place of the old one.

I think maybe someone done this before so i'd be happy for a solution ;)
If not i will try myself...
And the darkness begun...
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You should only drop those structures which you are allowed to drop, and also only once. For meshes, you might have to delete them from the mesh cache, which also holds a grab on the mesh. So I guess that you dropped the grab of the cache, but that one was still accessing the mesh (or dropped it upon program exit) and crashes then. But properly deleting the mesh from the cache should free the memory.
Gogolian
Posts: 32
Joined: Sat May 17, 2008 10:49 pm

Post by Gogolian »

so... uhm... maybe you can provide me a small example? ;)
And the darkness begun...
Gogolian
Posts: 32
Joined: Sat May 17, 2008 10:49 pm

Post by Gogolian »

oh, mighty people of Irrlicht, please share your insane knowledge, and help me solve my problem! Ame... Enter!:P
And the darkness begun...
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

No, I usually don't give code fragments. But I'd help you to improve yours. So just check the API for mesh cache and propose a first version.
Post Reply