Advertisement

Memory Leaks

Started by November 07, 2000 05:44 PM
5 comments, last by Spanky 24 years, 2 months ago
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 only know C, so I'll be embarrassed if this is just a syntax difference in ++, but right at the beginning are the lines:

TextureImage = meNew AUX_RGBImageRec;
if ( TextureImage = LoadBMP ( fileName ) )

Aren't you just throwing away the memory you allocated in that first line?

Edit: Is that possibly supposed to be TextureImage->data = LoadBMP?

Edited by - Ampere on November 7, 2000 10:41:44 PM
Advertisement
that is no fun for shure...

I dont use OpenGL though...

Keep conjuring the undead, my friends...
Keep conjuring the undead, my friends...
Ampere got it right there. You don''t have to allocate memory for TextureImage, it will be done for you when you call LoadBMP.
--------------------------Programmers don't byte, they nibble a bit. Unknown Person-------------------------
Thanks guy

Yeah, I was new''ing a new texture when I didn''t need to. I took that out and it all runs smooth and no memory leaks.

Thanks So Much

Shawn
Not directly related to the memory leak, but...

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
Advertisement
If you assign something to zero or NULL, then the result of the assignment statement will be FALSE, it is only TRUE if you assign to a non-zero value.


Please state the nature of the debugging emergency.


sharewaregames.20m.com

This topic is closed to new replies.

Advertisement