How do you test if a suface is used

I just want to note if you make a SDL_Surface *backbround and do not load an
image in it, then try to do standard clean up on exit you get a seg falt.

i.e.

void exit()
{
if ( background )
SDL_FreeSurface( background );
};

error: SDL Parachute Deployed

Then set this pointer to NULL initially. I assume it’s a global, declare it
like this:

SDL_Surface *background = NULL;

You are already checking if it’s null or not before you free it, so this is
all you are missing now.

-Jason> ----- Original Message -----

From: dryice@uswest.net (Corey Carter)
To:
Sent: Sunday, March 24, 2002 4:42 AM
Subject: [SDL] How do you test if a suface is used

I just want to note if you make a SDL_Surface *backbround and do not load
an
image in it, then try to do standard clean up on exit you get a seg falt.

i.e.

void exit()
{
if ( background )
SDL_FreeSurface( background );
};

error: SDL Parachute Deployed


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

Corey Carter wrote:

I just want to note if you make a SDL_Surface *backbround and do not load an
image in it, then try to do standard clean up on exit you get a seg falt.

i.e.

void exit()
{
if ( background )
SDL_FreeSurface( background );
};

error: SDL Parachute Deployed


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

I do :

if (background != NULL)
SDL_FreeSurface(background);

(Maybe it will work better?)

if ( background )
SDL_FreeSurface( background );

I do :

if (background != NULL)
SDL_FreeSurface(background);

(Maybe it will work better?)

No, these are exactly the same really. Won’t make any difference.

----- Original Message -----
From: mangoman@kitsuneaye.co.uk (MangoMan)
To:
Sent: Sunday, March 24, 2002 7:27 AM
Subject: Re: [SDL] How do you test if a suface is used

| I do :
|
| if (background != NULL)
| SDL_FreeSurface(background);
|
| (Maybe it will work better?)

That can cause problems…

If you declare background like this:

SDL_Surface *background;

it points at some random memory location. If you then don’t use
’background’ and try to free() it, you may end up free()ing a random
bit of memory. This will quite probably crash your program.On Sun, Mar 24, 2002 at 12:27:11PM +0000, MangoMan wrote:


Wedgies are unhealthy for children & other living things
6AD6 865A BF6E 76BB 1FC2 | www.piku.org.uk/public-key.asc
E4C4 DEEA 7D08 D511 E149 | www.piku.org.uk wnzrf at cvxh.bet.hx (rot13’d)