Flush all window events after SDL_CreateRenderer()

This commit is contained in:
Cameron Gutman 2020-05-12 18:41:36 -07:00
parent 2aa18dc88f
commit b4548c1af2
2 changed files with 14 additions and 0 deletions

View file

@ -1251,6 +1251,12 @@ void Session::exec(int displayOriginX, int displayOriginY)
SDL_SetWindowPosition(m_Window, x, y);
}
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
"Recreating renderer for window event: %d (%d %d)",
event.window.event,
event.window.data1,
event.window.data2);
// Fall through
case SDL_RENDER_DEVICE_RESET:
case SDL_RENDER_TARGETS_RESET:

View file

@ -177,6 +177,14 @@ bool SdlRenderer::initialize(PDECODER_PARAMETERS params)
return false;
}
// SDL_CreateRenderer() can end up having to recreate our window (SDL_RecreateWindow())
// to ensure it's compatible with the renderer's OpenGL context. If that happens, we
// can get spurious SDL_WINDOWEVENT events that will cause us to (again) recreate our
// renderer. This can lead to an infinite to renderer recreation, so discard all
// SDL_WINDOWEVENT events after SDL_CreateRenderer().
SDL_PumpEvents();
SDL_FlushEvent(SDL_WINDOWEVENT);
// Calculate the video region size, scaling to fill the output size while
// preserving the aspect ratio of the video stream.
SDL_Rect src, dst;