View Full Version : Free AUX_RGBImageRec ressource impossible

04-18-2012, 12:46 PM
I have a huge problem with openGL programs.

Actually when I get create a AUX_RGBImageRec* with a malloc or thanks a function from OpenGL libraries, it is impossible for removing it with a free.

So I think you can understand that it is a problem for me especially for memory management and I really don't understand why.

Has somebody an idea to help me with this problem or is there somebody who has already met that?


04-18-2012, 04:39 PM
This isn't even an OpenGL question. Allocating and freeing memory is something you learned when you started programming in C/C++. I'd suggest getting rid of that ancient library Glaux and start using something a little more modern like FreeImage, SOIL, or DeVIL, or write your own loader.

04-19-2012, 01:58 AM
Thank you for your answer but I need to use this structure especially and trust me I know how works allocation memory that's why I have a problem.
Why desallocation does not work with this glaux structure.
I tried asking solution to some friends very good in programming I I think I have good programming capacities too. So if I ask help to people of this forum it is because I have already searched a solution everywhere.

So if everybody has another idea.

Thank you.

04-19-2012, 02:06 AM
I would like be more accurate:

actually I can't free the structure if I use this function:

AUX_RGBImageRec* example = auxDIBImageLoad(filename);

free(example); //doesn't work

I tried too delete although glaux is a C library instead of free but it doesn't work too.


Alfonse Reinheart
04-19-2012, 09:03 AM
I need to use this structure especially

I'm curious: what circumstances have put you in the position that you need to use GLaux? Because I can't imagine those being good circumstances.

Dan Bartlett
04-19-2012, 09:21 AM
Looking at http://nehe.gamedev.net/tutorial/texture_mapping/12038/ , they use:

if (TextureImage[0]) // If Texture Exists
if (TextureImage[0]->data) // If Texture Image Exists
free(TextureImage[0]->data); // Free The Texture Image Memory

free(TextureImage[0]); // Free The Image Structure
so do you need to free "example->data" before freeing "example"?

04-19-2012, 12:35 PM
No very interesting circumstances, I just need to know how to use it perfectly for a project and because I want to know it too^^

I know that SOIL library is better but glaux is lower level in programmation that's why I prefer it; to get more control if you prefer. But this problem of free will provok memory leak so it is a serious problem if I want to do something very professionnal.

Alfonse Reinheart
04-19-2012, 03:15 PM
but glaux is lower level in programmation that's why I prefer it

Low level, high level, it doesn't matter; it's trash. It's garbage code that hasn't been updated or even touched in over a decade.

You shouldn't judge code based on whether it's low level or high level. You should judge code based on whether it's API makes sense, whether it does what it's supposed to, and how well supported it is.

GLaux has a crappy API, doesn't support many image formats, and hasn't been touched since the phrase "DOT COM" was coined.

it is a serious problem if I want to do something very professionnal.

If you wanted to do something "professionnal[sic]", you wouldn't be using GLaux. Professionals use real libraries, libraries that are supported by people.

04-20-2012, 01:25 AM
so do you need to free "example->data" before freeing "example"?

Yes of course I need to free that before but if I free that before it doesn't work too. It seems that compiler thinks the data address was not created thanks to malloc. Why not. But I really don't understand because it seems that only I meet this problem.
I tried to copied an existing code like NEHE's example but I meet the same problem...