Sign in to follow this  
Taymo

SDL_DisplayFormat error

Recommended Posts

Taymo    122
Ok I have one SDL_Surface in my class. Before I just had:
bases[baseToLoad].img = SDL_LoadBMP(filename);
But then I switched to:
      SDL_Surface *temp;
      temp = SDL_LoadBMP(filename);
      bases[baseToLoad].img = SDL_DisplayFormat(temp);
      SDL_FreeSurface(temp);
After the switch in code it compiles fine but I get a runtime error. Whats wrong?

Share this post


Link to post
Share on other sites
Drew_Benton    1861
First thing you can check is to make sure the image was loaded:

SDL_Surface *temp = 0;
temp = SDL_LoadBMP(filename);
if(!temp)
abort();
bases[baseToLoad].img = SDL_DisplayFormat(temp);
SDL_FreeSurface(temp);



If you run that and it aborts, then you know the problem. Otherwise, make sure that this code is not being called before SDL is initialized and you have created your primary screen. SDL_DisplayFormat makes a reference to the pixel format of the SDL's main screen, you make that with SDL_SetVideoMode, so if that code gets called before a call to SDL_SetVideoMode, then it will crash. Try those two things 1st and we can go from there.

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