Fixes for some memory leaks in the RTS-SK
by Geom · in RTS Starter Kit · 01/08/2008 (6:37 pm) · 2 replies
The RTS-Starter Kit is based off of Torque 1.3, so it has the same memory leaks that Torque 1.3 had. Since I'm currently tracking down and fixing these leaks for my game, I thought I'd post a summary of them here for the benefit of others.
Note, if you can port the RTS-SK to the latest version of Torque (1.5.2), you'd probably be better off going that route, rather than applying these fixes piecemeal. It's just that some of us (well, me at least) are married to the 1.3 code base, so people in my situation might find this list handy.
0. Not a leak per se, but this is a really nice article on how to find memory leaks in Torque:
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=6552
1. Leak of particle emitters in explosions; see the 9th post in the thread for the fix.
www.garagegames.com/mg/forums/result.thread.php?qt=21534
2. Leak of particle emitters on ShapeBase objects
www.garagegames.com/mg/forums/result.thread.php?qt=22614
(also includes a 2nd leak fix for interiors, but RTSs prolly don't care about that)
3. Leak of FileStream objects, when reading ZIP files (this might be specific to reading encrypted ZIP files, I'm not sure :-/ )
In engine/core/resManager.cc, replace the implementation of ResManager::closeStream() with
4. Another leak of FileStream objects:
Again in resManager.cc, find the line in ResManager::openStream()
and replace it with
5. Leak of DTS billboard bitmaps - note, this only affects you if you're using DTSs that have billboard detail levels, which is not all that common
In engine/ts/tsLastDetail.cc, find the line in TSLastDetail::TSLastDetail()
and replace it with
If I find more I'll post them as well. Feel free to add your own here as you find them (but keep the thread specific to memory leaks)
Note, if you can port the RTS-SK to the latest version of Torque (1.5.2), you'd probably be better off going that route, rather than applying these fixes piecemeal. It's just that some of us (well, me at least) are married to the 1.3 code base, so people in my situation might find this list handy.
0. Not a leak per se, but this is a really nice article on how to find memory leaks in Torque:
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=6552
1. Leak of particle emitters in explosions; see the 9th post in the thread for the fix.
www.garagegames.com/mg/forums/result.thread.php?qt=21534
2. Leak of particle emitters on ShapeBase objects
www.garagegames.com/mg/forums/result.thread.php?qt=22614
(also includes a 2nd leak fix for interiors, but RTSs prolly don't care about that)
3. Leak of FileStream objects, when reading ZIP files (this might be specific to reading encrypted ZIP files, I'm not sure :-/ )
In engine/core/resManager.cc, replace the implementation of ResManager::closeStream() with
void ResManager::closeStream (Stream * stream)
{
// Try to cast the stream to a FilterStream
FilterStream* subStream = dynamic_cast<FilterStream*>(stream);
// While the sub-stream is valid (meaning it was successfully cast to a FilterStream)
while (subStream)
{
// Point stream to the Stream contained within the current FilterStream
stream = subStream->getStream();
// Detach the sub-stream FilterStream from the Stream contained within it
subStream->detachStream();
// Delete the FilterStream that was wrapping stream
delete subStream;
// Try to cast the stream (which was already contained within a FilterStream) to a FilterStream
subStream = dynamic_cast<FilterStream*>(stream);
}
delete stream;
}4. Another leak of FileStream objects:
Again in resManager.cc, find the line in ResManager::openStream()
diskStream->open (buildPath (obj->path, obj->name), FileStream::Read);
and replace it with
if (!diskStream->open(buildPath (obj->path, obj->name), FileStream::Read)) {
delete diskStream;
return NULL;
}5. Leak of DTS billboard bitmaps - note, this only affects you if you're using DTSs that have billboard detail levels, which is not all that common
In engine/ts/tsLastDetail.cc, find the line in TSLastDetail::TSLastDetail()
mTextures[i] = new TextureHandle(NULL,mBitmaps[i],true);
and replace it with
mTextures[i] = new TextureHandle(NULL,mBitmaps[i],RegisteredTexture,true);
If I find more I'll post them as well. Feel free to add your own here as you find them (but keep the thread specific to memory leaks)
About the author
My email address is my GG handle, at redbrickgames.com.
#2
in Tgea 1.7.1 , SFX profile has Big Memory Leak.
after create a SFX profile, when delete it memory does not be free.
please help me.
01/17/2009 (8:27 am)
hi Geomin Tgea 1.7.1 , SFX profile has Big Memory Leak.
after create a SFX profile, when delete it memory does not be free.
please help me.
Torque 3D Owner Novack
CyberianSoftware