[Question] How do you unload everything to save memory?

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.
lokiare
Posts: 40
Joined: Wed Feb 04, 2009 5:40 pm

[Question] How do you unload everything to save memory?

Post by lokiare »

How do you unload everything when you change to a different "Map" as most games do? I've seen a few functions, but my program crashes after changing maps a few times. Is there some standard method of removing everything from memory? Note that I'm running on 20mb of ram, so I am using very small levels with just a few meshes and changing levels often to give the appearance of a vast area.
radical-dev
Posts: 45
Joined: Thu Apr 24, 2008 7:54 pm
Location: Wickede, Germany

Post by radical-dev »

Look at:

ISceneManager->clear()
IVideoDriver->removeAllTextures()
IGUIEnvironment->clear()
lokiare
Posts: 40
Joined: Wed Feb 04, 2009 5:40 pm

Post by lokiare »

I've tried using the first two, but my game still crashes after going through several "portals" (changing levels). If you use ISceneManager->clear() does it un-cache the loaded meshes too? I also used IVideoDriver->removeAllDynamicLights() or something to that effect.

would I be better off just restarting the engine?
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

smgr->getMeshCache()->clear();

That'll remove all the meshes that have previously been loaded.

Careful when removing the textures with removeAllTextures as they may still be referenced throughout your program. They're not reference counted like meshes and nodes!
Image Image Image
lokiare
Posts: 40
Joined: Wed Feb 04, 2009 5:40 pm

Post by lokiare »

Ok, thanks. I'll try everything listed and get back to you.
lokiare
Posts: 40
Joined: Wed Feb 04, 2009 5:40 pm

Post by lokiare »

Ok my DestroyScene function looks like this:

Code: Select all

bool GamePlayState::DestroyScene(void)
{
	// Clears all scene data
	smgr->clear();

	// Clear mobs
	meshes.clear();

        // Mobs is my custom "Character" class for holding character data
	mobs.clear();

        // Removes all the selectors
	metaSelector->removeAllTriangleSelectors();
	metaSelector->drop();
	metaSelector = 0;
	mapSelector = 0;

        // Set all meshes to 0
	levelMesh = 0;
	levelNode = 0;
	levelData = 0;

        // Removes all impacts and shots
	Impacts.clear();
	if (psShot)
		psShot->drop();
	psShot = 0;
	return true;
}
With the above code I can load levels 20 times before I get a crash...

When I try to use smgr->getMeshCache()->clear() I get the following error:

Code: Select all

GamePlayState.cpp: In member function 'bool GamePlayState::DestroyScene()':
GamePlayState.cpp:1583: error: invalid use of incomplete type 'struct engine::sc
ene::IMeshCache'
../../../usr/local/pspdev/psp/include/LTE/ISceneManager.h:102: error: forward de
claration of 'struct engine::scene::IMeshCache'
make: *** [GamePlayState.o] Error 1
I take this to mean that my copy of the engine is not compiled correctly?
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

The compile error tells you that you are trying to use an incomplete type scene::IMeshCache. This means that you need to include the header that defines the class IMeshCache, which is IMeshCache.h. If you are already including irrlicht.h, you shouldn't need to do this, but there is always the chance that someone didn't put it in there. If that is the case you'd need to include it explicitly.

Travis
lokiare
Posts: 40
Joined: Wed Feb 04, 2009 5:40 pm

Post by lokiare »

I had to re-implement the mesh cache (all of the classes used "class CMeshCache" as their implementation, and IMeshCache had nothing implemented). Once I put it back in properly and re-built the library it worked fine (I changed levels 56 times before I stopped counting) with just using:

Code: Select all

// levelmesh is my level mesh
smgr->getMeshCache()->removeMesh(levelMesh);
smgr->getMeshCache()->removeMesh(levelDataMesh);
These being the only two that I want to unload to save memory (I will probably in the future want to unload things specific to each level also).
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

I think you still lack very basic C++ knowledge. There's absolutely no need to reimplement the meshcache. Moreover, any duplication of mesh caches would mean that you also duplicate the meshes, since none of the Irrlicht mesh loading code would use your meshcache. I think you use a reference to IMeshCache somewhere, instead of a pointer to IMeshCache, which would already solve the compiler problem.
lokiare
Posts: 40
Joined: Wed Feb 04, 2009 5:40 pm

Post by lokiare »

When I say "re-implement" I mean fix the fact that whoever ported and compiled the engine use forward declarations for MeshCache throughout the code, and the "real" MeshCache was not implemented as part of the program. So when I would go to compile, it would give me forward declaration errors. Sorry if I was not clear.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Sorry, I still don't get it. You shouldn't need to get in touch with any place which uses CMeshCache. The only thing you need to deal with is IMeshCache, and you must use pointers to those classes, because it's an interface, i.e. (partially) abstract classes.
porcus
Posts: 149
Joined: Sun May 27, 2007 6:24 pm
Location: Germany

Post by porcus »

You could call device->drop(); and then create a new device
for your new map.
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

It seems he is using some Irrlicht version ported to PSP and something went wrong in the porting process. (You can even see his namespaces are weird "engine::scene::IMeshCache"?)
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

That could be caused by someone accidentally putting an include inside a namespace declaration. I'm still betting that there is a CMeshCache implementation in there somewhere and that he doesn't understand that the IMeshCache is just an interface that isn't supposed to be fully implemented.

Travis
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Oh yes, LTE. Sorry, this completely broken rip-off is not supported to any extent in this forum. Please ask the folks from LTE.
Post Reply