I am currently working on an OpenGL project and have just been hunting down memory leaks over the past few hours. I got them all except for one thats generated in this secion of code. The TextureImage pointer is what is causing the memory leak. I thought I free''d everything down at the bottom but I guess I was wrong. Any ideas?
PS - I know the code is s**t but hey, what can you do right? I am just learning and experimenting so please don''t flame me on it. Any suggestions to it would be nice though
int F3D_Texture::LoadNewTexture( char fileName[] )
{
int Status = NULL;
texture_t *texture;
AUX_RGBImageRec *TextureImage;
TextureImage = meNew AUX_RGBImageRec;
texture = meNew texture_t;
if ( TextureImage = LoadBMP ( fileName ) )
{
Status = TRUE;
glGenTextures ( 1, &texture->texture ); // Create The Texture
// Typical Texture Generation Using Data From A Bitmap
glBindTexture ( GL_TEXTURE_2D, texture->texture );
// Generate The Texture
glTexImage2D ( GL_TEXTURE_2D, 0, 3, TextureImage->sizeX, TextureImage->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage->data );
glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); // Linear Filtering
glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); // Linear Filtering
}
this->totalTextures++;
texture->textID = this->totalTextures;
strcpy ( texture->fileName, fileName );
Textures.insert ( TextMap::value_type ( texture->textID, texture->texture ) );
if ( TextureImage ) // If Texture Exists
{
if ( TextureImage->data ) // If Texture Image Exists
meDelete TextureImage->data; // Free The Texutre Image Memory
meDelete TextureImage; // Free The Image Structure
}
meDelete texture;
return Status;
}
Here is the code that I also use with this function to load images
//////////////////////////////////////////////////////////////////////
// Uses the Auxilary library to load a BMP (to be changed)
//////////////////////////////////////////////////////////////////////
AUX_RGBImageRec* F3D_Texture::LoadBMP(char *Filename)
{
FILE* File = NULL;
if ( !Filename )
{
return NULL;
}
File = fopen ( Filename, "r" );
if ( File )
{
fclose ( File );
return auxDIBImageLoad ( Filename );
}
return NULL;
}
I''m curious about the use of an assignation within the if statement. If I remember my C++ syntax correctly, your if statement is always true. What was the intent of that particular statement?
"Don''t tell me how hard you work. Tell me how much you get done." - James J. Ling