ref: 16441ee87b5256243766b9a5f49de5cf93be314f
parent: 0bd968d78d4532582aec02439b409e5f08466e52
author: Gabriel Ravier <[email protected]>
date: Sat Apr 11 12:57:04 EDT 2020
Backends: Improved miniaudio and GLFW3 error handling Signed-off-by: Gabriel Ravier <[email protected]>
--- 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 @@
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 @@
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);
--- a/src/Backends/GLFW3/Controller.cpp
+++ b/src/Backends/GLFW3/Controller.cpp
@@ -8,6 +8,7 @@
#include <GLFW/glfw3.h>
#include "../../WindowsWrapper.h"
+#include "../Misc.h"
#define DEADZONE (10000.0f / 32767.0f)
@@ -21,7 +22,7 @@
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 @@
// 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 @@
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);
--- a/src/Backends/GLFW3/Misc.cpp
+++ b/src/Backends/GLFW3/Misc.cpp
@@ -152,8 +152,15 @@
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;
--- a/src/Backends/GLFW3/Window-OpenGL3.cpp
+++ b/src/Backends/GLFW3/Window-OpenGL3.cpp
@@ -71,7 +71,7 @@
}
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