Streaming ogg memory leak (Source for fix included)
by Richard McKinney · in Torque Game Builder · 11/02/2006 (10:20 am) · 0 replies
There is a bug in the streaming ogg code that causes a 532,480 byte memory leak every time a streaming ogg is started and stopped. You can see more details on the bug here: http://www.garagegames.com/mg/forums/result.thread.php?qt=53193
Code to fix this leak follows. You can just add two lines to VorbisStreamSource, but I changed it like this:
In audio/VorbisStreamSource.h, add the following line in the private section (just above clearBuffers() is fine):
in VorbisStreamSource::Clear() change
If you're lazy you could just add that call to alSourceUnqueueBuffers() to both freeStream() and clear() instead of calling deleteBuffers().
Code to fix this leak follows. You can just add two lines to VorbisStreamSource, but I changed it like this:
In audio/VorbisStreamSource.h, add the following line in the private section (just above clearBuffers() is fine):
void deleteBuffers();In audio/VorbisStreamSource.cc:
in VorbisStreamSource::Clear() change
if(mBufferList[0] != 0)
alDeleteBuffers(NUMBUFFERS, mBufferList);
for(int i = 0; i < NUMBUFFERS; i++)
mBufferList[i] = 0;todeleteBuffers();in VorbisStreamSource::freeStream() change
if(mBufferList[0] != 0)
alDeleteBuffers(NUMBUFFERS, mBufferList);
for(int i = 0; i < NUMBUFFERS; i++)
mBufferList[i] = 0;todeleteBuffers();and finally add the deleteBuffers method just below VorbisStreamSource::freeStream():
void VorbisStreamSource::deleteBuffers()
{
// Ensure that the refCount on the buffers is zero:
alSourceUnqueueBuffers (mSource, NUMBUFFERS, mBufferList);
if(mBufferList[0] != 0)
alDeleteBuffers(NUMBUFFERS, mBufferList);
for(int i = 0; i < NUMBUFFERS; i++)
mBufferList[i] = 0;
}If you're lazy you could just add that call to alSourceUnqueueBuffers() to both freeStream() and clear() instead of calling deleteBuffers().
About the author