diff --git a/src/Backends/Audio/miniaudio.cpp b/src/Backends/Audio/miniaudio.cpp index ce2b8582..34cc6799 100644 --- a/src/Backends/Audio/miniaudio.cpp +++ b/src/Backends/Audio/miniaudio.cpp @@ -9,6 +9,7 @@ #include "../../Organya.h" #include "../../WindowsWrapper.h" +#include "../Misc.h" #include "SoftwareMixer.h" @@ -80,13 +81,19 @@ BOOL AudioBackend_Init(void) config.dataCallback = Callback; config.pUserData = NULL; - if (ma_device_init(NULL, &config, &device) == MA_SUCCESS) + ma_result return_value; + + return_value = ma_device_init(NULL, &config, &device); + if (return_value == MA_SUCCESS) { - if (ma_mutex_init(device.pContext, &mutex) == MA_SUCCESS) + return_value = ma_mutex_init(device.pContext, &mutex); + if (return_value == MA_SUCCESS) { - if (ma_mutex_init(device.pContext, &organya_mutex) == MA_SUCCESS) + return_value = ma_mutex_init(device.pContext, &organya_mutex); + if (return_value == MA_SUCCESS) { - if (ma_device_start(&device) == MA_SUCCESS) + return_value = ma_device_start(&device); + if (return_value == MA_SUCCESS) { output_frequency = device.sampleRate; @@ -94,22 +101,43 @@ BOOL AudioBackend_Init(void) return TRUE; } + else + { + Backend_PrintError("Failed to start playback device: %s", ma_result_description(return_value)); + } ma_mutex_uninit(&organya_mutex); } + else + { + Backend_PrintError("Failed to create organya mutex: %s", ma_result_description(return_value)); + } ma_mutex_uninit(&mutex); } + else + { + Backend_PrintError("Failed to create mutex: %s", ma_result_description(return_value)); + } ma_device_uninit(&device); } + else + { + Backend_PrintError("Failed to initialize playback device: %s", ma_result_description(return_value)); + } + return FALSE; } void AudioBackend_Deinit(void) { - ma_device_stop(&device); + ma_result return_value; + return_value = ma_device_stop(&device); + + if (return_value != MA_SUCCESS) + Backend_PrintError("Failed to stop playback device: %s", ma_result_description(return_value)); ma_mutex_uninit(&organya_mutex); diff --git a/src/Backends/GLFW3/Controller.cpp b/src/Backends/GLFW3/Controller.cpp index b5c55dc2..7220c0c6 100644 --- a/src/Backends/GLFW3/Controller.cpp +++ b/src/Backends/GLFW3/Controller.cpp @@ -8,6 +8,7 @@ #include #include "../../WindowsWrapper.h" +#include "../Misc.h" #define DEADZONE (10000.0f / 32767.0f) @@ -21,7 +22,7 @@ static void JoystickCallback(int joystick_id, int event) switch (event) { case GLFW_CONNECTED: - printf("Joystick #%d connected - %s\n", joystick_id, glfwGetJoystickName(joystick_id)); + Backend_PrintInfo("Joystick #%d connected - %s", joystick_id, glfwGetJoystickName(joystick_id)); if (!joystick_connected) { @@ -44,8 +45,13 @@ static void JoystickCallback(int joystick_id, int event) // Set up neutral axes axis_neutrals = (float*)malloc(sizeof(float) * total_axes); - for (int i = 0; i < total_axes; ++i) - axis_neutrals[i] = axes[i]; + if (axis_neutrals) + { + for (int i = 0; i < total_axes; ++i) + axis_neutrals[i] = axes[i]; + } + else + Backend_PrintError("Couldn't allocate memory for axis"); } } } @@ -55,7 +61,7 @@ static void JoystickCallback(int joystick_id, int event) case GLFW_DISCONNECTED: if (joystick_connected && joystick_id == connected_joystick_id) { - printf("Joystick #%d disconnected\n", connected_joystick_id); + Backend_PrintInfo("Joystick #%d disconnected", connected_joystick_id); joystick_connected = FALSE; free(axis_neutrals); diff --git a/src/Backends/GLFW3/Misc.cpp b/src/Backends/GLFW3/Misc.cpp index bac11777..6665d98c 100644 --- a/src/Backends/GLFW3/Misc.cpp +++ b/src/Backends/GLFW3/Misc.cpp @@ -152,8 +152,15 @@ static void DragAndDropCallback(GLFWwindow *window, int count, const char **path LoadProfile(paths[0]); } +static void ErrorCallback(int code, const char *description) +{ + Backend_PrintError("GLFW error received (%d) : %s", code, description); +} + BOOL Backend_Init(void) { + glfwSetErrorCallback(ErrorCallback); + if (glfwInit() == GL_TRUE) return TRUE; diff --git a/src/Backends/GLFW3/Window-OpenGL3.cpp b/src/Backends/GLFW3/Window-OpenGL3.cpp index 07130be1..4dbfc5cd 100644 --- a/src/Backends/GLFW3/Window-OpenGL3.cpp +++ b/src/Backends/GLFW3/Window-OpenGL3.cpp @@ -71,7 +71,7 @@ BOOL WindowBackend_OpenGL_CreateWindow(const char *window_title, int *screen_wid } else { - Backend_ShowMessageBox("Fatal error (OpenGL rendering backend)", "Could not load OpenGL functions"); + Backend_ShowMessageBox("Fatal error (OpenGL rendering backend)", "Could not initialize OpenGL context"); } #endif