From fbe613ce5c13e4d80f82dc4a7783056dd28b1ee0 Mon Sep 17 00:00:00 2001 From: Misa Date: Sat, 28 Jan 2023 23:41:44 -0800 Subject: [PATCH] Abort and print error if window/renderer cannot be created This aborts and prints the error from SDL_GetError() if SDL_CreateWindow() or SDL_CreateRenderer() fails. We abort because there's not much point in continuing if the window or renderer can't be created. There might be a use case for running the game in headless mode, but let's code that in explicitly if we ever want it. --- desktop_version/src/Screen.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/desktop_version/src/Screen.cpp b/desktop_version/src/Screen.cpp index d4fd3ce6..fc8f0114 100644 --- a/desktop_version/src/Screen.cpp +++ b/desktop_version/src/Screen.cpp @@ -5,6 +5,7 @@ #include "Alloc.h" #include "Constants.h" +#include "Exit.h" #include "FileSystemUtils.h" #include "Game.h" #include "Graphics.h" @@ -56,8 +57,20 @@ void Screen::init(const struct ScreenSettings* settings) SDL_WINDOW_HIDDEN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI ); + if (m_window == NULL) + { + vlog_error("Could not create window: %s", SDL_GetError()); + VVV_exit(1); + } + m_renderer = SDL_CreateRenderer(m_window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE); + if (m_renderer == NULL) + { + vlog_error("Could not create renderer: %s", SDL_GetError()); + VVV_exit(1); + } + #ifdef INTERIM_VERSION_EXISTS /* Branch name limits are ill-defined but on GitHub it's ~256 chars * ( https://stackoverflow.com/a/24014513/ ).