Sign in to follow this  
psiko_scweek

Can someone check this SDL code?

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this