mirror of https://github.com/mgba-emu/mgba.git
SDL: Ensure that the emulation loop cannot end between a redraw and an SDL event poll
This commit is contained in:
parent
65d74a2e34
commit
e7fa65f876
|
@ -130,6 +130,10 @@ void GBASDLRunloop(struct GBAThread* context, struct SDLSoftwareRenderer* render
|
|||
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 @@ void GBASDLRunloop(struct GBAThread* context, struct SDLSoftwareRenderer* render
|
|||
eglSwapBuffers(renderer->display, renderer->surface);
|
||||
}
|
||||
GBASyncWaitFrameEnd(&context->sync);
|
||||
|
||||
while (SDL_PollEvent(&event)) {
|
||||
GBASDLHandleEvent(context, &renderer->events, &event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -83,6 +83,18 @@ void GBASDLRunloop(struct GBAThread* context, struct SDLSoftwareRenderer* render
|
|||
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 @@ void GBASDLRunloop(struct GBAThread* context, struct SDLSoftwareRenderer* render
|
|||
#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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -60,6 +60,10 @@ void GBASDLRunloop(struct GBAThread* context, struct SDLSoftwareRenderer* render
|
|||
#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 @@ void GBASDLRunloop(struct GBAThread* context, struct SDLSoftwareRenderer* render
|
|||
#endif
|
||||
}
|
||||
GBASyncWaitFrameEnd(&context->sync);
|
||||
|
||||
while (SDL_PollEvent(&event)) {
|
||||
GBASDLHandleEvent(context, &renderer->events, &event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue