From 58fc9a392ac3d868292eebdc0991247a9bca03be Mon Sep 17 00:00:00 2001 From: Clownacy Date: Mon, 13 Apr 2020 13:56:29 +0100 Subject: [PATCH] More cleanup --- src/Backends/SDL2/Controller.cpp | 18 ++++++++++++------ src/Backends/SDL2/Misc.cpp | 28 ++++++++++++++++++---------- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/Backends/SDL2/Controller.cpp b/src/Backends/SDL2/Controller.cpp index 3d0687d1..d91200d4 100644 --- a/src/Backends/SDL2/Controller.cpp +++ b/src/Backends/SDL2/Controller.cpp @@ -6,8 +6,8 @@ #include "SDL.h" -#include "../../WindowsWrapper.h" #include "../Misc.h" +#include "../../WindowsWrapper.h" #define DEADZONE 10000 @@ -142,6 +142,7 @@ BOOL ControllerBackend_ResetJoystickStatus(void) void ControllerBackend_JoystickConnect(Sint32 joystick_id) { const char *joystick_name = SDL_JoystickNameForIndex(joystick_id); + if (joystick_name != NULL) { Backend_PrintInfo("Joystick #%d connected - %s", joystick_id, joystick_name); @@ -172,17 +173,22 @@ void ControllerBackend_JoystickConnect(Sint32 joystick_id) // Set up neutral axes axis_neutrals = (Sint16*)malloc(sizeof(Sint16) * total_axes); + if (axis_neutrals != NULL) + { for (int i = 0; i < total_axes; ++i) axis_neutrals[i] = SDL_JoystickGetAxis(joystick, i); + + return; + } else + { Backend_PrintError("Couldn't allocate memory for neutral axes"); + } } - else - { - SDL_JoystickClose(joystick); - joystick = NULL; - } + + SDL_JoystickClose(joystick); + joystick = NULL; } else { diff --git a/src/Backends/SDL2/Misc.cpp b/src/Backends/SDL2/Misc.cpp index cc5b3ae6..16e78623 100644 --- a/src/Backends/SDL2/Misc.cpp +++ b/src/Backends/SDL2/Misc.cpp @@ -45,22 +45,29 @@ BOOL Backend_Init(void) const char *driver = SDL_GetCurrentVideoDriver(); if (driver != NULL) + { Backend_PrintInfo("Selected SDL video driver: %s", driver); - else - Backend_PrintError("No SDL video driver initialized !"); - return TRUE; + return TRUE; + } + else + { + Backend_PrintError("No SDL video driver initialized!"); + } + } + else + { + std::string error_message = std::string("Could not initialise SDL video subsystem: ") + SDL_GetError(); + Backend_ShowMessageBox("Fatal error", error_message.c_str()); } - std::string error_message = std::string("Could not initialise SDL video subsystem: ") + SDL_GetError(); - Backend_ShowMessageBox("Fatal error", error_message.c_str()); - SDL_Quit(); - return FALSE; } - - std::string error_message = std::string("Could not initialise SDL: ") + SDL_GetError(); - Backend_ShowMessageBox("Fatal error", error_message.c_str()); + else + { + std::string error_message = std::string("Could not initialise SDL: ") + SDL_GetError(); + Backend_ShowMessageBox("Fatal error", error_message.c_str()); + } return FALSE; } @@ -301,6 +308,7 @@ void Backend_GetKeyboardState(BOOL *out_keyboard_state) void Backend_ShowMessageBox(const char *title, const char *message) { fprintf(stderr, "ShowMessageBox - '%s' - '%s'\n", title, message); + if (SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, title, message, window) != 0) Backend_PrintError("Was also unable to display a message box containing the error: %s", SDL_GetError()); }