Swapping/unloading meshes

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
nano
Posts: 25
Joined: Mon May 07, 2007 1:12 pm

Swapping/unloading meshes

Post by nano »

I'm having a similar problem to this thread http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=17913 it was the closest i could find to what i wanted.

I'm trying to remove a map and then load another one. This is the code:

Code: Select all

IAnimatedMesh* trackMesh;
	ISceneNode* trackNode;

	if (!initRun){
		//load map
		trackMesh = smgr->getMesh(trackFilename);
		
		if (trackMesh)
			trackNode = smgr->addOctTreeSceneNode(trackMesh->getMesh(0));
		else printf("Error: Mesh could not be loaded\n.");
	} else {
		trackNode->remove();

		trackMesh = smgr->getMesh(trackFilename);
		if (trackMesh)
			trackNode = smgr->addOctTreeSceneNode(trackMesh->getMesh(0));
		else printf("Error: Mesh could not be loaded\n.");
	}
It works fine on the first run through (where !initRun) but when i try to remove the node it just crashes the program.

All i want it to do is remove the currently loaded map and put in the new one but without this code it just keeps putting them inside eachother and with this code the program crashes =/

I've tried various combinations of removeMesh, remove() removeAll() and drop() but still havent come across a way that both compiles and does not crash when run. Help would be greatly appreciated.
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

Just guessing here...

Code: Select all

// make sure you set pointers to null
IAnimatedMesh* trackMesh=0;
ISceneNode* trackNode=0;

...

// make sure you check everything before using it
if (trackNode)
{
  trackNode->remove();
  // and remember the state of the pointer
  trackNode = 0;
}
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
nano
Posts: 25
Joined: Mon May 07, 2007 1:12 pm

Post by nano »

Starting from your suggestion i began changing things around and now it works perfectly, thank you!
Post Reply