Freeing surfaces created with SDL_CreateRGBSurfaceFrom(...)

Hi All,

How can I, within the SDL_Surface structure, check to see if I need to
free the pixel buffer seperately?? The reason I need this is because I
have made a loader for a custom graphics file format, and I am creating
the surface by using SDL_CreateRGBSurfaceFrom(). The documentation says
that SDL_FreeSurface will not free the pixel buffer in such case.
Correct?

Regards
Anders of Denmark

Hi All,

How can I, within the SDL_Surface structure, check to see if I need to
free the pixel buffer seperately?? The reason I need this is because I
have made a loader for a custom graphics file format, and I am creating
the surface by using SDL_CreateRGBSurfaceFrom(). The documentation says
that SDL_FreeSurface will not free the pixel buffer in such case.
Correct?

Correct.
If you pass in memory, you are responsible for tracking and freeing it yourself.

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

the surface by using SDL_CreateRGBSurfaceFrom(). The documentation
says

that SDL_FreeSurface will not free the pixel buffer in such case.
Correct?

Correct.
If you pass in memory, you are responsible for tracking and freeing it
yourself.

Thanks Sam,

Then what if I put the surface through a SDL_ConvertSurface() to stick
it in video memory??

I experimented and found out that I am able to always free the pixel
buffer separately and stick the pointer in SDL_Surface structure to
null, before calling SDL_FreeSurface. Will this be sufficient?

Regards
AndersFrom: slouken@libsdl.org (slouken)

Then what if I put the surface through a SDL_ConvertSurface() to stick
it in video memory??

The conversion always creates a new surface and leaves the old one untouched.

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

Sam Lantinga wrote:

The conversion always creates a new surface and leaves the old one
untouched.

Yes I realise that, but how should I free the new surface? With
SDL_FreeSurface() alone?

Regards
Anders