Page 1 of 2

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

Posted: Tue Feb 17, 2009 4:15 am
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.

Posted: Tue Feb 17, 2009 7:55 am
by radical-dev
Look at:

ISceneManager->clear()
IVideoDriver->removeAllTextures()
IGUIEnvironment->clear()

Posted: Tue Feb 17, 2009 4:21 pm
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?

Posted: Tue Feb 17, 2009 4:30 pm
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!

Posted: Tue Feb 17, 2009 5:06 pm
by lokiare
Ok, thanks. I'll try everything listed and get back to you.

Posted: Wed Feb 18, 2009 6:37 am
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?

Posted: Wed Feb 18, 2009 7:26 am
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

Posted: Sun Feb 22, 2009 12:42 am
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).

Posted: Sun Feb 22, 2009 12:46 pm
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.

Posted: Sun Feb 22, 2009 7:59 pm
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.

Posted: Sun Feb 22, 2009 10:14 pm
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.

Posted: Sun Feb 22, 2009 10:51 pm
by porcus
You could call device->drop(); and then create a new device
for your new map.

Posted: Mon Feb 23, 2009 3:26 am
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"?)

Posted: Mon Feb 23, 2009 3:54 am
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

Posted: Mon Feb 23, 2009 9:06 am
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.