FreeSurface calls

Hi all,

A newbee here as a first poster, I think. :slight_smile:

I am just eager to know the co-relation to SDL_FreeSurface() and
IMG_Load(), a call from SDL_image. It seems when I read this mailinglist
that SDL_FreeSurface() calls is only related to SDL_LoadBMP() calls?

Right or wrong?

Why I am asking, is that ( I’m a newbee allover C & SDL ) when I try to
free up the surfaces loaded with IMG_Load(), the whole program takes a
parachute. When the loaded surfaces are not freed everythings just
works. Just like SDL_image takes care of business?

Some thoughts that would be nice to get some info about…Happy bug
hunting!
/Patrich

I am just eager to know the co-relation to SDL_FreeSurface() and
IMG_Load(), a call from SDL_image. It seems when I read this
mailinglist
that SDL_FreeSurface() calls is only related to SDL_LoadBMP()
calls?

I don’t use SDL_image so I can’t help you there, but you should use
SDL_FreeSurface on any surface that you allocate, except the main
surface that you get back from SDL_SetVideoMode. You should free any
surfaces that you create using SDL_LoadBMP, SDL_CreateRGBSurface,
SDL_DisplayFormat, etc. (Basically any function that gives you back
a new SDL_Surface object, except SDL_SetVideoMode. That surface is
automatically freed by SDL_Quoit.)–
Matthijs Hollemans
All Your Software
www.allyoursoftware.com

I am just eager to know the co-relation to SDL_FreeSurface() and
IMG_Load(), a call from SDL_image. It seems when I read this
mailinglist
that SDL_FreeSurface() calls is only related to SDL_LoadBMP()
calls?

I don’t use SDL_image so I can’t help you there, but you should use
SDL_FreeSurface on any surface that you allocate, except the main
surface that you get back from SDL_SetVideoMode. You should free any
surfaces that you create using SDL_LoadBMP, SDL_CreateRGBSurface,
SDL_DisplayFormat, etc. (Basically any function that gives you back
a new SDL_Surface object, except SDL_SetVideoMode. That surface is
automatically freed by SDL_Quoit.)

This is true of surfaces created with SDL_image as well. If your program
crashes when freeing them, you are either freeing them twice, or you
probably have some other unrelated memory corruption problem.

Good luck!
-Sam Lantinga, Software Engineer, Blizzard Entertainment

tor 2002-10-17 klockan 19.12 skrev Sam Lantinga:

I am just eager to know the co-relation to SDL_FreeSurface() and
IMG_Load(), a call from SDL_image. It seems when I read this
mailinglist
that SDL_FreeSurface() calls is only related to SDL_LoadBMP()
calls?

I don’t use SDL_image so I can’t help you there, but you should use
SDL_FreeSurface on any surface that you allocate, except the main
surface that you get back from SDL_SetVideoMode. You should free any
surfaces that you create using SDL_LoadBMP, SDL_CreateRGBSurface,
SDL_DisplayFormat, etc. (Basically any function that gives you back
a new SDL_Surface object, except SDL_SetVideoMode. That surface is
automatically freed by SDL_Quoit.)

This is true of surfaces created with SDL_image as well. If your program
crashes when freeing them, you are either freeing them twice, or you
probably have some other unrelated memory corruption problem.

Good luck!
-Sam Lantinga, Software Engineer, Blizzard Entertainment


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Wow, now that wasnt fun to hear. l Well, I have rdram, 2x256 MB
(Pentium IV) and, how is a good approach to find if there is any errors
in memory? Or do you talk about the gfx memory on my 3D-card? (Sparkle
GF2 MX400/200, 64MB).

I allso tried freeing in a tutorial on the libsdl pages, and got the
same result. I will try on another machine if I just get the posibility
to it…try out to make a simple image-load prog to see if there is
something I have forbeseen or not.

Thanks for all the feedbacks. Appreciated!
/Patrich

Wow, now that wasnt fun to hear. l Well, I have rdram, 2x256 MB
(Pentium IV) and, how is a good approach to find if there is any errors
in memory? Or do you talk about the gfx memory on my 3D-card? (Sparkle
GF2 MX400/200, 64MB).

What I meant was that your program is probably writing over memory that
is being used elsewhere in your program, not that the physical memory is
bad.

I allso tried freeing in a tutorial on the libsdl pages, and got the
same result. I will try on another machine if I just get the posibility
to it…try out to make a simple image-load prog to see if there is
something I have forbeseen or not.

Take a look at showimage.c in the SDL_image source archive, it should
show how you can load and free an image surface using SDL_image and
SDL_FreeSurface().

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment