1
0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-06-03 03:23:33 +02:00

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.
This commit is contained in:
Misa 2023-01-28 23:41:44 -08:00
parent 2525017990
commit fbe613ce5c

View File

@ -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/ ).