I'm having serious memory problems!!!
I load some bitmaps for textures, good! But, the memory used by the =
LoadBMP(char *filename) function isn't released!! So, when I load =
textures under program run several times, the memory just vanishes in my =
app. Even though I load the same ones, into the same pointers. What can =
i do?
My LoadTexture-source is below;
Thanks!
AUX_RGBImageRec *LoadBMP(char *filename)
{
FILE *file=3DNULL;
if(!filename)
return NULL;
file =3D fopen(filename, "r");
if(file)
{
fclose(file);
return auxDIBImageLoad(filename);
}
return NULL;
}
int LoadGLTexture(char path[81], GLuint &texture)
{
int Status =3D TRUE;
AUX_RGBImageRec *TextureImage[1];
memset(TextureImage, 0, sizeof(void *)*1);
if(TextureImage[0] =3D LoadBMP(path))
{
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, =
TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, =
TextureImage[0]->data);
if(Settings.Texturing =3D=3D 1)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, =
GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, =
GL_NEAREST);
}
else if(Settings.Texturing =3D=3D 2)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, =
GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, =
GL_LINEAR);
}
else if(Settings.Texturing =3D=3D 3)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, =
GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, =
GL_LINEAR_MIPMAP_LINEAR);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]->sizeX, =
TextureImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, =
TextureImage[0]->data);
}
}
else
Status =3D FALSE;
if(TextureImage)
{
if(TextureImage[0]->data)
free(TextureImage[0]->data);
free(TextureImage);
}
return Status;
}
|