Lemmons
Lemmons

Reputation: 1806

SDL "dropping" initial event?

I'm programming things with SDL 1.2 on Ubuntu 12.04. SDL appears to "drop" the first event given to the event loop. For example, if I were to check for quitting the game via the "x" box, and I click said "x" box in my application, nothing happens. However upon a second click the game quits. My game loop:

void game_run()
{
    int RUNNING = 1;

    while(RUNNING == 1)
    {
        while(SDL_PollEvent(&scr.event))
        {
            switch(scr.event.type)
            {
                case SDL_QUIT:
                RUNNING = 0;
                break;

                case SDL_KEYDOWN:
                switch(scr.event.key.keysym.sym)
                {
                    case SDLK_ESCAPE:
                    RUNNING = 0;
                    break;

                    default:
                    break;
                }
                break;

                default:
                break;
            }
        }

        // draw here

        SDL_Flip(scr.buffer);
    }
}

If any more information is needed, please let me know!

Upvotes: 0

Views: 94

Answers (1)

user1944441
user1944441

Reputation:

Change your

case SDL_QUIT:
RUNNING = 0;
break;

to

case SDL_QUIT:
exit( 0 ) ;
break;

The program should exit immediately, confirming that the event loop works fine and problem is somewhere in your code you haven't shown. My guess is game_run() is called again somewhere, and because int RUNNING = 1; is set at the beginning of every game_run(), your enter another while(RUNNING == 1) loop.

Upvotes: 2

Related Questions