SDL_DisplayFormat error

Recommended Posts

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;
SDL_FreeSurface(temp);
After the switch in code it compiles fine but I get a runtime error. Whats wrong?

Share on other sites
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 on other sites
Ahhh hah! Yes it is being called before I setup the main screen. Thanks a bunch man.

Create an account

Register a new account

• Forum Statistics

• Total Topics
628316
• Total Posts
2982032

• 9
• 9
• 13
• 11
• 14