# Can someone check this SDL code?

This topic is 4270 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Can anyone tell me if this code is wrong?
[SOURCE]
void gmp_splashscreenrun(SDL_Surface *splashtemp)
{
SplashScreen.setGraphic(splashtemp);
SplashScreen.setX((SCR_W/2)-(SplashScreen.getGraphicWidth()/2));
SplashScreen.setY((SCR_H/2)-(SplashScreen.getGraphicHeight()/2));
for(int i = 0;i<255;i++)
{
SDL_FillRect( gfx_screen, &gfx_screen->clip_rect, SDL_MapRGB( gfx_screen->format, 0xFF, 0xFF, 0xFF ) );
SDL_SetAlpha(SplashScreen.graphic, SDL_SRCALPHA, i);
SDL_Delay(10);
if (i == 254)
{SDL_Delay(25);}
SplashScreen.draw();
gfx_flipscreen();
}
for(int i = 255;i>0;i--)
{
SDL_FillRect( gfx_screen, &gfx_screen->clip_rect, SDL_MapRGB( gfx_screen->format, 0xFF, 0xFF, 0xFF ) );
SDL_SetAlpha(SplashScreen.graphic, SDL_SRCALPHA, i);
SDL_Delay(10);
if (i == 1)
{SDL_Delay(25);}
SplashScreen.draw();
gfx_flipscreen();
}
SDL_FreeSurface(SplashScreen.graphic);
}
[/SOURCE]
[/source] as far as I know there is not a problem with it, it compliles ok, but it crashes whenever it tries to Free the Surface

##### Share on other sites
I can't see anything wrong that would cause a crash. Check that you aren't freeing the surface again in the SplashScreen destructor.

Good Luck.

##### Share on other sites
is the destructor being called though? Ill check to see if the destructor is removing the SDL surface.

other than that, the code looks good?

thanks again

ok,

I checked and I dont have the destructor calling the SDL_FreeSurface.

but I thought about it, would it be better to call have it? how does this code look?

void gmp_splashscreenrun(SDL_Surface *splashtemp){Object SplashScreen;SplashScreen.setGraphic(splashtemp);SplashScreen.setX((SCR_W/2)-(SplashScreen.getGraphicWidth()/2));SplashScreen.setY((SCR_H/2)-(SplashScreen.getGraphicHeight()/2));for(int i = 0;i<255;i++)   {   SDL_FillRect( gfx_screen, &gfx_screen->clip_rect, SDL_MapRGB( gfx_screen->format, 0xFF, 0xFF, 0xFF ) );   SDL_SetAlpha(SplashScreen.graphic, SDL_SRCALPHA, i);   SDL_Delay(10);   if (i == 254)   {SDL_Delay(25);}   SplashScreen.draw();   gfx_flipscreen();   }for(int i = 255;i>0;i--)   {   SDL_FillRect( gfx_screen, &gfx_screen->clip_rect, SDL_MapRGB( gfx_screen->format, 0xFF, 0xFF, 0xFF ) );   SDL_SetAlpha(SplashScreen.graphic, SDL_SRCALPHA, i);   SDL_Delay(10);   if (i == 1)   {SDL_Delay(25);}   SplashScreen.draw();   gfx_flipscreen();   }}

with the destructor
/////////// SETUP THE OBJECTS DESTRUCTOR ///////////Object::~Object(){if (graphic != NULL)   {SDL_FreeSurface(graphic);}}

oh yeah the game still crashes whenever it completes the function. i dont understand why! its when i call the SDL_FreeSurface....

[Edited by - psiko_scweek on October 9, 2006 10:49:18 PM]

##### Share on other sites
Show where and how you call gmp_splashscreenrun().

##### Share on other sites
Try running SDL in software mode and see if that gets rid if your troubles. Do this by passing SDL_SWSURFACE to SDL_SetVideoMode in place of SDL_HWSURFACE and SDL_DOUBLEBUF.

I have had this exact problem before when using hardware surfaces.

##### Share on other sites
To OP: I didn't realise you posted here as well.

I tried out the code that you posted at DCEmu and can't find any problems with it. It loads the image, fades it in, fades it out and exits the program cleanly.

• 48
• 12
• 10
• 10
• 9
• ### Forum Statistics

• Total Topics
631380
• Total Posts
2999672
×