[Question] How do you unload everything to save memory?
[Question] How do you unload everything to save memory?
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.
-
- Posts: 45
- Joined: Thu Apr 24, 2008 7:54 pm
- Location: Wickede, Germany
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?
would I be better off just restarting the engine?
Ok my DestroyScene function looks like this:
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:
I take this to mean that my copy of the engine is not compiled correctly?
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;
}
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
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
Travis
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:
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).
Code: Select all
// levelmesh is my level mesh
smgr->getMeshCache()->removeMesh(levelMesh);
smgr->getMeshCache()->removeMesh(levelDataMesh);
-
- Admin
- Posts: 14143
- Joined: Wed Apr 19, 2006 9:20 pm
- Location: Oldenburg(Oldb), Germany
- Contact:
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.
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.
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
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net