ctor
ctor

Reputation: 6128

SDL_PeepEvents won't handle window close

I am calling SDL_PeepEvents( sdlevent, EVENT_BUFFER_SIZE, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_SYSWMEVENT ); however after a few seconds of runtime and mucking around with the window (resizing/moving/minimizing) it won't pick up an event when the x is clicked to close window.

void Window::pollWindowEvents(  )
{
    const int EVENT_BUFFER_SIZE = 16;
    SDL_Event sdlevent[ EVENT_BUFFER_SIZE ];    //The SDL event that we will poll to get events.

    SDL_PumpEvents(  );
    int numEvents = SDL_PeepEvents( sdlevent, EVENT_BUFFER_SIZE, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_SYSWMEVENT );

    std::cout << numEvents << std::endl;

    for ( int i = 0; i < numEvents; ++i )
    {
        switch ( sdlevent[ i ].type )
        {
        case SDL_QUIT:
            closed = true;
            std::cout << sdlevent[ i ].type << std::endl;
            break;
        default:
            std::cout << sdlevent[ i ].type << std::endl;
            break;
        };
    }
}

Does anyone know what I'm doing wrong?

Upvotes: 3

Views: 484

Answers (1)

ctor
ctor

Reputation: 6128

When calling SDL_PeepEvents() I was only processing a select range of events in the queue with the remaining events being unprocessed. This resulted in the event queue becoming saturated with these unprocessed events and as a result stopped the events I wanted to process from being processed. This was easily resolved by processing ALL events in the event queue.

Upvotes: 1

Related Questions