• Advertisement
Sign in to follow this  

SDL_Flip() crashing

This topic is 4549 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

Hi all! Here we go!!! SDL_Flip() seems to crash my program. I figured this by commenting out my line:
//app.Flip();
Now, here is that function:
void cApp_Flip() {SDL_Flip(m_Screen);}
m_Screen gets set up with this:
app.cApp_InitWindow(SCREEN_H, SCREEN_W, SDL_HWSURFACE | SDL_DOUBLEBUF)

//which is:
bool ret = (app.cApp_Init(SDL_INIT_VIDEO) &&
                app.cApp_InitWindow(SCREEN_H, SCREEN_W, SDL_HWSURFACE | SDL_DOUBLEBUF) &&
                app.cApp_AddImage("Paddle.bmp") &&
                app.cApp_AddImage("Paddle.bmp") &&
                app.cApp_AddImage("Ball.bmp"));


I AM using SDL_DOUBLEBUF, so that is not the case. So what can be a possible cause for SDL_Flip(..) failing? P.S. It seems that if I comment that line out my program does not draw my pictures, but DOES draw them when I draw the program under the start menu and back up...

Share this post


Link to post
Share on other sites
Advertisement
Chances are your m_Screen is NULL or some random value because you did not properly initilize it. Just to see if I'm right, try:
void cApp_Flip() {SDL_Flip(SDL_GetVideoSurface());}
If it works fine now, you will need to make your code assign m_Screen a proper value: m_Screen = SDL_GetVideoSurface(); after you initialize SDL and create your display window.

If it doesn't work, make sure that function is not being called before you initialize SDL and your display window.

Share this post


Link to post
Share on other sites
Quote:
Original post by Drew_Benton
Chances are your m_Screen is NULL or some random value because you did not properly initilize it. Just to see if I'm right, try:
void cApp_Flip() {SDL_Flip(SDL_GetVideoSurface());}
If it works fine now, you will need to make your code assign m_Screen a proper value: m_Screen = SDL_GetVideoSurface(); after you initialize SDL and create your display window.

If it doesn't work, make sure that function is not being called before you initialize SDL and your display window.


Good idea, but it still doesnt work. It crashes on that line.

I'm pretty sure m_Screen isnt null, or else my above code snippet's "ret" would be false and the program would quit before the flip...

Share this post


Link to post
Share on other sites
Quote:
Original post by dudedbz1
I'm pretty sure m_Screen isnt null, or else my above code snippet's "ret" would be false and the program would quit before the flip...


Oh ok, so in your cApp_InitWindow function, you have something like this:
m_Screen = SDL_SetVideoMode(SCREEN_W, SCREEN_H, bpp, flags)

Also just noting you pass in the heigth then the width 1st in your code, is your function handling that properly. Other than that, only reason I could see it crash is with an invalid surface, what do all your functions look like: cApp_Init, cApp_InitWindow, and cApp_AddImage. Also you might want to try not putting all of those in that one line, break it up to make sure things are getting called in the right order:
int error = 0;
error += app.cApp_Init(SDL_INIT_VIDEO);
error += app.cApp_InitWindow(SCREEN_H, SCREEN_W, SDL_HWSURFACE | SDL_DOUBLEBUF);
error += app.cApp_AddImage("Paddle.bmp");
error += app.cApp_AddImage("Paddle.bmp");
error += app.cApp_AddImage("Ball.bmp");


Now if error > 0, then one of them failed (assuming your return 0 on no error and 1 on error), and you are sure they all got called in the right order.

Share this post


Link to post
Share on other sites
Quote:
Original post by Drew_Benton
Quote:
Original post by dudedbz1
I'm pretty sure m_Screen isnt null, or else my above code snippet's "ret" would be false and the program would quit before the flip...


Oh ok, so in your cApp_InitWindow function, you have something like this:
m_Screen = SDL_SetVideoMode(SCREEN_W, SCREEN_H, bpp, flags)

Also just noting you pass in the heigth then the width 1st in your code, is your function handling that properly. Other than that, only reason I could see it crash is with an invalid surface, what do all your functions look like: cApp_Init, cApp_InitWindow, and cApp_AddImage. Also you might want to try not putting all of those in that one line, break it up to make sure things are getting called in the right order:
int error = 0;
error += app.cApp_Init(SDL_INIT_VIDEO);
error += app.cApp_InitWindow(SCREEN_H, SCREEN_W, SDL_HWSURFACE | SDL_DOUBLEBUF);
error += app.cApp_AddImage("Paddle.bmp");
error += app.cApp_AddImage("Paddle.bmp");
error += app.cApp_AddImage("Ball.bmp");


Now if error > 0, then one of them failed (assuming your return 0 on no error and 1 on error), and you are sure they all got called in the right order.


Hmmm... I changed my Init function so that everything is called in order, but it still doest work, so I changed it back. Its not the problem most likely anyways, since cApp_AddImage(...) doesnt really need SDL, just the drawing does.

The screen width and height is most likely correct, but it doesnt really matter since for now both my height and width are 500 pixels... Here are the functions:

bool cApp::cApp_Init(unsigned int flags, bool text)
{
if (SDL_Init(flags) == -1)
return false;

if (text)
{
if (TTF_Init() == -1)
return false;

_TextOn = true;
}
else
_TextOn = false;

return true;
}

bool cApp::cApp_InitWindow(int h, int w, unsigned int flags)
{
m_Screen = SDL_SetVideoMode(w, h, 0, flags);

if (m_Screen == NULL)
return false;

return true;
}

bool cApp::cApp_AddImage(const char *fileName)
{
Image *imageToAdd = new Image;

imageToAdd->SetSprite(IMG_Load(fileName));

if (imageToAdd->GetSprite() == NULL)
{
delete imageToAdd;

return false;
}

m_Graphics.push_back(imageToAdd);

return true;
}



They all have error checking(true or false), and according to what they return, they are all true. Paddle.bmp and Ball.bmp exist.

The cApp_Draw(...) function does not fail, because if I comment out the flipping it works... I dont know what might be the bug...

P.S. I dont know if it is of any help, but it looks like when I comment out the flipping and when I draw the app below the start bar and up again everything is drawn. It isnt at the beginning.

Share this post


Link to post
Share on other sites
This might not be the problem but make sure m_Screen isnt locked.

Also when your program crashes do you get an error message?

Share this post


Link to post
Share on other sites
Nope, nothing. No error, no debugger message, nothing, just quits. Why would m_Screen be locked? I've used it before without doing anything to it and it worked. How can I unlock it?

Share this post


Link to post
Share on other sites
SDL_Flip returns an int.

if its -1 then there was an error.

if theres an error then cout << SDL_GetError() << endl;

also, you might want to try

SDL_UpdateRect( SDL_GetVideoSurface() , 0, 0, 0, 0)

it an alternative to SDL_Flip, but doesnt do double buffering. you could try it out though to see if it still crashes. BTW, there is nothing in sdterr.txt, is there?

do you ever call SDL_LockSurface( m_screen ) ? thats the only reason i could think of it failing...

Share this post


Link to post
Share on other sites
Quote:
Original post by rip-off
SDL_Flip returns an int.

if its -1 then there was an error.

if theres an error then cout << SDL_GetError() << endl;

also, you might want to try

SDL_UpdateRect( SDL_GetVideoSurface() , 0, 0, 0, 0)

it an alternative to SDL_Flip, but doesnt do double buffering. you could try it out though to see if it still crashes. BTW, there is nothing in sdterr.txt, is there?

do you ever call SDL_LockSurface( m_screen ) ? thats the only reason i could think of it failing...


YES YES YES!!! Thanks sooo much.

Anyways, SDL_UpdateRect(...) works... But why? I'm using SDL_DOUBLEBUF, so why would it work and SDL_Flip() fail? The screen is not locked. There is nothing in stderr.txt. Anyone have any ideas why?

Share this post


Link to post
Share on other sites
Quote:
Original post by dudedbz1
Quote:
Original post by rip-off
SDL_Flip returns an int.

if its -1 then there was an error.

if theres an error then cout << SDL_GetError() << endl;

also, you might want to try

SDL_UpdateRect( SDL_GetVideoSurface() , 0, 0, 0, 0)

it an alternative to SDL_Flip, but doesnt do double buffering. you could try it out though to see if it still crashes. BTW, there is nothing in sdterr.txt, is there?

do you ever call SDL_LockSurface( m_screen ) ? thats the only reason i could think of it failing...


YES YES YES!!! Thanks sooo much.

Anyways, SDL_UpdateRect(...) works... But why? I'm using SDL_DOUBLEBUF, so why would it work and SDL_Flip() fail? The screen is not locked. There is nothing in stderr.txt. Anyone have any ideas why?


So, anyone have an idea why UpdateRect might work but SDL_Flip doesnt?

Share this post


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

  • Advertisement