Jump to content
  • Advertisement
Sign in to follow this  
psiko_scweek

Can someone check this SDL code?

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

If you intended to correct an error in the post then please contact us.

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
Advertisement
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 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
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!