SDL_QUIT problem

I’m having a VERY strange SDL_QUIT problem with SDL1.2.6 in Win32. My game
is checking for SDL_QUIT messages to shutdown, but something very strange
is happening. If I leave the game on the title screen for some time, it
will simply shutdown out of the blue (yep, no error messages, parachutes or
other stuff). I checked about everything in my code, so I’m sure the bug is
not mine (maybe it’s a problem in Windows, not in SDL). The final test was
to check if there was an SDL_QUIT message actually sent, and yes, I’ve got
on my code an SDL_QUIT message, when there was nothing going on. The
program shutdowns properly, only problem is that it shouldn’t be doing so.

I tried it on Mac OS X and it worked wih no problem, it only got the 

SDL_QUIT message when I closed the window. Does anyone had similar
problems? The most strange is that it will happen only when it’s idle, not
playing the game, so I can play for longer than half an hour and it’s fine,
but if I leave it on my title screen loop it will shut down after just some
minutes.

Paulo

It’s very difficult to say without seeing your code. :frowning: And lots of people
use SDL under Win32 without it generating spontaneous SDL_QUIT messages,
so I wonder if it still is in your code somehow. A couple things come to
mind:

-Are you using SDL_PushEvent anywhere? You might be inserting an SDL_QUIT
message into the que by accident.
-Check your logic around where it responds to the SDL_QUIT message. If you’re
using a switch statement, is there a missing ‘break’ anywhere? It could be
falling through from the above case.On Wednesday 10 September 2003 06:47 pm, Paulo V W Radtke wrote:

I’m having a VERY strange SDL_QUIT problem with SDL1.2.6 in Win32. My game
is checking for SDL_QUIT messages to shutdown, but something very strange
is happening. If I leave the game on the title screen for some time, it
will simply shutdown out of the blue (yep, no error messages, parachutes or
other stuff). I checked about everything in my code, so I’m sure the bug is
not mine (maybe it’s a problem in Windows, not in SDL). The final test was
to check if there was an SDL_QUIT message actually sent, and yes, I’ve got
on my code an SDL_QUIT message, when there was nothing going on. The
program shutdowns properly, only problem is that it shouldn’t be doing so.

I tried it on Mac OS X and it worked wih no problem, it only got the
SDL_QUIT message when I closed the window. Does anyone had similar
problems? The most strange is that it will happen only when it’s idle, not
playing the game, so I can play for longer than half an hour and it’s fine,
but if I leave it on my title screen loop it will shut down after just some
minutes.

Paulo


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

It’s very difficult to say without seeing your code. :frowning:

Be my guest :). Here’s the function that handle the SDL events in my game. The QUIT variable
indicates that the game should shutdown and is set to true ONLY when the handle event function gets
an SDL_QUIT event. I checked to see if the program was actually getting an SDL_QUIT event (the
printf) and it was.

void handleInput()
{
SDL_Event event;
SDL_PollEvent( &event );
/* We are only worried about SDL_KEYDOWN and SDL_KEYUP events */
switch( event.type )
{
case SDL_QUIT:
printf("\nGot an SDL_QUIT\n");
QUIT=true;
break;

      case SDL_KEYDOWN:
                switch(event.key.keysym.sym)
                {
                          case SDLK_LCTRL:
                          case SDLK_SPACE:
                          case SDLK_LALT:                              
                          	TIRO1 = true;
                          	break;

                          case SDLK_UP:
                          	CIMA=true;
                          	break;

                          case SDLK_DOWN:
                          	BAIXO=true;
                          	break;

                          case SDLK_RIGHT:
                          	DIREITA=true;
                          	break;

                          case SDLK_LEFT:
                          	ESQUERDA=true;
                          	break;

                          case SDLK_F1:
                          	PAUSA=!PAUSA;
                          	break;

                          case SDLK_ESCAPE:
                            printf("\nPressed ESQ\n");
                          	ESC=true;
                          	break;
                          	
                          default:                              	
                          	break;

                }
                break;
                                    
      case SDL_KEYUP:
                switch(event.key.keysym.sym)
                {
                          case SDLK_LCTRL:
                          case SDLK_SPACE:
                          	TIRO1 = false;
                          	break;

                          case SDLK_LALT:
                          	TIRO2=false;
                          	break;

                          case SDLK_UP:
                          	CIMA=false;
                          	break;

                          case SDLK_DOWN:
                          	BAIXO=false;
                          	break;

                          case SDLK_RIGHT:
                          	DIREITA=false;
                          	break;

                          case SDLK_LEFT:
                          	ESQUERDA=false;
                          	break;

                          default:                              	
                          	break;

                }

                break;

      default:
                break;
 }

}

And lots of people
use SDL under Win32 without it generating spontaneous SDL_QUIT messages,

I was once like that too. It started to happen after I started to work with SDL 1.2.6 (I never noticed it
when using SDL 1.2.4) and ported the game engine to Open GL. The SDL_QUIT is generated only when
the game is REALLY on a idle state, ie, no input on the keyboard or mouse being directed to my game.
I played it for a way longer time than it takes to crash (it takes about 5 minutes to shutdown by itself)
and nothing strange happened. But once I left it alone, it happened again. It also happens if I leave it
running on the background while using Word or any other program, so I’m also sure that the system
is not going to hybernate, turning off the hard disk, etc.

-Are you using SDL_PushEvent anywhere? You might be inserting an SDL_QUIT
message into the que by accident.

No, no SDL_PushEvent anywhere on my code.

-Check your logic around where it responds to the SDL_QUIT message. If you’re
using a switch statement, is there a missing ‘break’ anywhere? It could be
falling through from the above case.

Nope, you can check that on the code. I also think it’s strange, but I tried again just now and guess
what? Runned for about 5 minutes and then it simply finishes execution. I would say that it’s
something with my programming if the same would happen on MAC OS X. But it doesn’t, wich means
that either Windows XP, the SDL build or MingW32 are at fault. Just to let know, I’m using the
developer version 1.2.6 for mingw32 (Dev C++) and the runtime 1.2.6 copied to the system32
Windows directory.

Well, if anyone has some thoughts on that, I’m all ears :).

Paulo

Are you sure it’s quiting due to an SDL_QUIT being issued?

Your code looks fine… is there any variable in your main loop that may
be overflowing? Any other functions that may be taking it down? Memory
leaks, bad allocation, etc.

Since you say no SDL parachute was deployed etc. what is the exit status
of the programm?

-Mike

Here’s your problem:

void handleInput()
{
SDL_Event event;
SDL_PollEvent( &event );
/* We are only worried about SDL_KEYDOWN and SDL_KEYUP events */
switch( event.type )

You need to check the return value of SDL_PollEvent(), when there are no
events you’ll get whatever happened to be on the stack in the event variable.

It should be:
while ( SDL_PollEvent(&event) ) {
switch(event.type) {
}
}

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment

Here’s your problem:

void handleInput()
{
SDL_Event event;
SDL_PollEvent( &event );
/* We are only worried about SDL_KEYDOWN and SDL_KEYUP events */
switch( event.type )

You need to check the return value of SDL_PollEvent(), when there are no
events you’ll get whatever happened to be on the stack in the event variable.

It should be:
while ( SDL_PollEvent(&event) ) {
switch(event.type) {
}
}
Maybe there should be an SDL_NoEvent grin – His code /should/ make
sense, and if there is no event…well, in either case, I’m for
versatility.

ChuckOn Thu, 11 Sep 2003, Sam Lantinga wrote:

Are you sure it’s quiting due to an SDL_QUIT being issued?

Yep, I inserted the printf just to be sure, and it does print the message.

Your code looks fine… is there any variable in your main loop that may
be overflowing? Any other functions that may be taking it down? Memory
leaks, bad allocation, etc.

I fixed one memory leak problem I had, but for this one I got an SDL parachute, so I don’t think it’s due to a problem like this. And like I said, the very same code (yep, I don’t need to change a single line) runs on Mac OS X just fine, I left the game running on the main title loop (title, splash ans high score table) for over an hour and I had no problem.

Since you say no SDL parachute was deployed etc. what is the exit status
of the programm?

Status 0 (no error).

I will try to rollback to an older version to see if the porblem happens again.

Paulo

You need to check the return value of SDL_PollEvent(), when there are no
events you’ll get whatever happened to be on the stack in the event variable.

It should be:
while ( SDL_PollEvent(&event) ) {
switch(event.type) {
}
}

O_O

Thanks Sam, I will try it later at home (I’m at work now). This bug haunted me for about a week, hopefully I’ll get it right now :).

Paulo

Maybe there should be an SDL_NoEvent grin – His code /should/ make
sense, and if there is no event…well, in either case, I’m for
versatility.

Chuck

Yeah, there is an SDL_NOEVENT in SDL_events.h. SDL_NOEVENT isn’t used though. So in SDL_PollEvent, before it returns a 0, it can set set event.type to SDL_NOEVENT. But I don’t like that idea exactly. Because other programs might depend on the event struct data being intact when PollEvent returns a zero because they are reusing an old, but valid, event struct. So, actually PollEvent doesn’t need to change. He could just initialize event with event.type = SDL_NOEVENT.

void handleInput()
{
SDL_Event event;
event.type = SDL_NOEVENT;
SDL_PollEvent( &event );
/* We are only worried about SDL_KEYDOWN and SDL_KEYUP events */
switch( event.type )

	Jesse

You need to check the return value of SDL_PollEvent(), when there are no
events you’ll get whatever happened to be on the stack in the event variable.

It should be:
while ( SDL_PollEvent(&event) ) {
switch(event.type) {
}
}

See ya,

     Just to let you know Sam, it's working flawlessly now. Been 

running for over half an hour and no “mysterious SDL_QUIT” events. Thanks
for the tip!

     Paulo