Page 1 of 1

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

Posted: Sun Jun 15, 2008 10:50 pm
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...

Posted: Mon Jun 16, 2008 8:16 am
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.

Posted: Wed Jun 18, 2008 10:23 am
by Gogolian
so... uhm... maybe you can provide me a small example? ;)

Posted: Thu Jun 19, 2008 10:49 am
by Gogolian
oh, mighty people of Irrlicht, please share your insane knowledge, and help me solve my problem! Ame... Enter!:P

Posted: Thu Jun 19, 2008 11:16 am
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.