all repos — mgba @ e7fa65f876fda26e6ea9b223b83de929fdd2b6c5

mGBA Game Boy Advance Emulator

SDL: Ensure that the emulation loop cannot end between a redraw and an SDL event poll
Jeffrey Pfau jeffrey@endrift.com
Thu, 27 Nov 2014 08:48:58 -0800
commit

e7fa65f876fda26e6ea9b223b83de929fdd2b6c5

parent

65d74a2e3465cda20832621c217f56744fd6d6d9

3 files changed, 20 insertions(+), 20 deletions(-)

jump to
M src/platform/sdl/egl-sdl.csrc/platform/sdl/egl-sdl.c

@@ -130,6 +130,10 @@ void GBASDLRunloop(struct GBAThread* context, struct SDLSoftwareRenderer* renderer) {

SDL_Event event; while (context->state < THREAD_EXITING) { + while (SDL_PollEvent(&event)) { + GBASDLHandleEvent(context, &renderer->events, &event); + } + if (GBASyncWaitFrameStart(&context->sync, context->frameskip)) { glViewport(0, 0, 240, 160); glClear(GL_COLOR_BUFFER_BIT);

@@ -145,10 +149,6 @@ glUseProgram(0);

eglSwapBuffers(renderer->display, renderer->surface); } GBASyncWaitFrameEnd(&context->sync); - - while (SDL_PollEvent(&event)) { - GBASDLHandleEvent(context, &renderer->events, &event); - } } }
M src/platform/sdl/gl-sdl.csrc/platform/sdl/gl-sdl.c

@@ -83,6 +83,18 @@ glMatrixMode (GL_PROJECTION);

glLoadIdentity(); glOrtho(0, VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS, 0, 0, 1); while (context->state < THREAD_EXITING) { + while (SDL_PollEvent(&event)) { + GBASDLHandleEvent(context, &renderer->events, &event); +#if SDL_VERSION_ATLEAST(2, 0, 0) + // Event handling can change the size of the screen + if (renderer->events.windowUpdated) { + SDL_GetWindowSize(renderer->window, &renderer->viewportWidth, &renderer->viewportHeight); + glViewport(0, 0, renderer->viewportWidth, renderer->viewportHeight); + renderer->events.windowUpdated = 0; + } +#endif + } + if (GBASyncWaitFrameStart(&context->sync, context->frameskip)) { glBindTexture(GL_TEXTURE_2D, renderer->tex); #ifdef COLOR_16_BIT

@@ -105,18 +117,6 @@ SDL_GL_SwapWindow(renderer->window);

#else SDL_GL_SwapBuffers(); #endif - - while (SDL_PollEvent(&event)) { - GBASDLHandleEvent(context, &renderer->events, &event); -#if SDL_VERSION_ATLEAST(2, 0, 0) - // Event handling can change the size of the screen - if (renderer->events.windowUpdated) { - SDL_GetWindowSize(renderer->window, &renderer->viewportWidth, &renderer->viewportHeight); - glViewport(0, 0, renderer->viewportWidth, renderer->viewportHeight); - renderer->events.windowUpdated = 0; - } -#endif - } } }
M src/platform/sdl/sw-sdl.csrc/platform/sdl/sw-sdl.c

@@ -60,6 +60,10 @@ SDL_Surface* surface = SDL_GetVideoSurface();

#endif while (context->state < THREAD_EXITING) { + while (SDL_PollEvent(&event)) { + GBASDLHandleEvent(context, &renderer->events, &event); + } + if (GBASyncWaitFrameStart(&context->sync, context->frameskip)) { #if SDL_VERSION_ATLEAST(2, 0, 0) SDL_UnlockTexture(renderer->tex);

@@ -88,10 +92,6 @@ SDL_LockSurface(surface);

#endif } GBASyncWaitFrameEnd(&context->sync); - - while (SDL_PollEvent(&event)) { - GBASDLHandleEvent(context, &renderer->events, &event); - } } }