mipmapping and memory leaks

Started by
0 comments, last by MarkS_ 11 years, 7 months ago
I've never played around with mipmapping so I thought I would give it a try. Everything works well, but gDEBugger reports "Memory Leak: 9 object(s) are leaked in GL Context 1" when it is deleted. The only thing that it can be are the nine mipmap levels, since no other GL objects are allocated.

This is the code I use to load the texture:
[source]
void LoadTestTexture(void)
{
long i;
string str;
texture *test_tex;
glGenTextures(1,&test_tex_ID);
glBindTexture(GL_TEXTURE_2D,test_tex_ID);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);
for(i = 0;i < 9;i++)
{
test_tex = new texture;
str = "data/";
str.append("level",5);
str.append(1,(char)(i + '0'));
str.append(".tga\0");
cout << str.c_str() << endl;
test_tex->LoadTexture(str.c_str());
cout << test_tex->GetImageWidth() << endl;
cout << test_tex->GetImageHeight() << endl;
glTexImage2D(GL_TEXTURE_2D,i,GL_RGBA,test_tex->GetImageWidth(),test_tex->GetImageHeight(),0,GL_RGBA,GL_UNSIGNED_BYTE,test_tex->GetImageData());
str.clear();
delete test_tex;
}
}
[/source]

I plan on using rendered textures, so I am loading the mipmap levels manually rather than relying on gluBuild2DMipmaps. As you can see, this function loads the texture file into memory, calls glTexImage2D and deletes the texture from system memory. When the program exits, I call glDeleteTextures on "test_tex_ID". Having no further control over the texture memory, I thought this would be enough.

The program is really very simple. I create the context, load the mipmaps and bind them and then draw a quad moving (using immediate mode for coding speed) towards and away from the camera to test the mipmaps. That's it. Other than the textures, no other GL objects are allocated and all allocated memory is deleted on program exit.

It seems like this leak is coming from the driver. Is this normal?
Advertisement
Never mind. I thought to look in the texture class and saw that "LoadTexture" called "glGenTextures" each time. It also failed to call "glDeleteTextures" in the destructor. I need to rewrite the texture class anyway.

Problem solved.

This topic is closed to new replies.

Advertisement