From ded1f41f810c25eac77899250d2223ea251a899f Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Sun, 25 Feb 2018 18:20:28 -0800 Subject: sdl_fb: drain event queue on page flip --- src/sdl_fb.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/sdl_fb.c b/src/sdl_fb.c index 52cf556..b663848 100644 --- a/src/sdl_fb.c +++ b/src/sdl_fb.c @@ -120,10 +120,31 @@ static int sdl_fb_page_free(void *context, void *page) } +static int sdl_ready() +{ + SDL_Event ev; + + /* It's important on Windows in particular to + * drain the event queue vs. just SDL_QuitRequested() + */ + while (SDL_PollEvent(&ev)) { + if (ev.type == SDL_QUIT) + return -EPIPE; + } + + return 0; +} + + static int sdl_fb_page_flip(void *context, void *page) { sdl_fb_t *c = context; sdl_fb_page_t *p = page; + int r; + + r = sdl_ready(); + if (r < 0) + return r; if (SDL_UpdateTexture(c->texture, NULL, p->surface->pixels, p->surface->pitch) < 0) return -1; @@ -136,9 +157,6 @@ static int sdl_fb_page_flip(void *context, void *page) SDL_RenderPresent(c->renderer); - if (SDL_QuitRequested()) - return -EPIPE; - return 0; } -- cgit v1.2.3