From 997363ce56424905355abcff7b43e4d063dbfb17 Mon Sep 17 00:00:00 2001 From: Misa Date: Sat, 12 Mar 2022 16:47:23 -0800 Subject: [PATCH] `GetWindowSize`: Initialize out values if `GetRendererOutput` fails Issue #870 showed one of the problems that this game has, namely that it only sometimes checks SDL return values, and did not do so in this case. Part of the cause of #870 is that Screen::GetWindowSize does not check the return value of SDL_GetRendererOutputSize, so when that function fails (as in the case where m_renderer is NULL and does not exist), it does not initialize the out values, so it ends up writing uninitialized values to the save files. We need to make sure every function's return value is checked, not just SDL functions, but that will have to be done later. --- desktop_version/src/Screen.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/desktop_version/src/Screen.cpp b/desktop_version/src/Screen.cpp index bf65105f..709523cc 100644 --- a/desktop_version/src/Screen.cpp +++ b/desktop_version/src/Screen.cpp @@ -253,7 +253,13 @@ void Screen::ResizeToNearestMultiple(void) void Screen::GetWindowSize(int* x, int* y) { - SDL_GetRendererOutputSize(m_renderer, x, y); + if (SDL_GetRendererOutputSize(m_renderer, x, y) != 0) + { + vlog_error("Could not get window size: %s", SDL_GetError()); + /* Initialize to safe defaults */ + *x = SCREEN_WIDTH_PIXELS; + *y = SCREEN_HEIGHT_PIXELS; + } } void Screen::UpdateScreen(SDL_Surface* buffer, SDL_Rect* rect )