ref: 41d5c5b5c8fc3cc0766c6e01e4e020b1c4a15440
parent: 7d65d009ffd1923b83f1c5e75c8046815956e5ab
author: Clownacy <Clownacy@users.noreply.github.com>
date: Tue Apr 7 13:46:02 EDT 2020
Make it so `Backend_Init` can fail
--- a/src/Backends/GLFW3/Misc.cpp
+++ b/src/Backends/GLFW3/Misc.cpp
@@ -150,9 +150,12 @@
LoadProfile(paths[0]);
}
-void Backend_Init(void)
+BOOL Backend_Init(void)
{
- glfwInit();
+ if (glfwInit() == GL_TRUE)
+ return TRUE;
+ else
+ return FALSE;
}
void Backend_Deinit(void)
--- a/src/Backends/Misc.h
+++ b/src/Backends/Misc.h
@@ -85,7 +85,7 @@
extern BOOL bActive;
-void Backend_Init(void);
+BOOL Backend_Init(void);
void Backend_Deinit(void);
void Backend_PostWindowCreation(void);
BOOL Backend_GetBasePath(char *string_buffer);
--- a/src/Backends/SDL2/Misc.cpp
+++ b/src/Backends/SDL2/Misc.cpp
@@ -30,21 +30,29 @@
static SDL_Surface *cursor_surface;
static SDL_Cursor *cursor;
-void Backend_Init(void)
+BOOL Backend_Init(void)
{
- SDL_Init(SDL_INIT_EVENTS);
+ if (SDL_Init(SDL_INIT_EVENTS) == 0)
+ {
+ if (SDL_InitSubSystem(SDL_INIT_VIDEO) == 0)
+ {
+ puts("Available SDL2 video drivers:");
- SDL_InitSubSystem(SDL_INIT_VIDEO);
+ for (int i = 0; i < SDL_GetNumVideoDrivers(); ++i)
+ puts(SDL_GetVideoDriver(i));
- puts("Available SDL2 video drivers:");
+ const char *driver = SDL_GetCurrentVideoDriver();
- for (int i = 0; i < SDL_GetNumVideoDrivers(); ++i)
- puts(SDL_GetVideoDriver(i));
+ if (driver != NULL)
+ printf("Selected SDL2 video driver: %s\n", driver);
- const char *driver = SDL_GetCurrentVideoDriver();
+ return TRUE;
+ }
- if (driver != NULL)
- printf("Selected SDL2 video driver: %s\n", driver);
+ SDL_Quit();
+ }
+
+ return FALSE;
}
void Backend_Deinit(void)
--- a/src/Main.cpp
+++ b/src/Main.cpp
@@ -88,7 +88,8 @@
int i;
- Backend_Init();
+ if (!Backend_Init())
+ return EXIT_FAILURE;
// Get executable's path
if (!Backend_GetBasePath(gModulePath))