shithub: cstory

Download patch

ref: 8e2d8ab962016d78ce1e39d4dd6c0448147b4e96
parent: bf8d824b70ca837f39e9983adfa04c243876f7ae
author: Clownacy <Clownacy@users.noreply.github.com>
date: Fri Apr 24 13:06:53 EDT 2020

Add context initialisation to miniaudio backend

This is used for mutexes in the enhanced backend

--- a/src/Backends/Audio/miniaudio.cpp
+++ b/src/Backends/Audio/miniaudio.cpp
@@ -82,52 +82,63 @@
 
 	ma_result return_value;
 
-	return_value = ma_device_init(NULL, &config, &device);
+	return_value = ma_context_init(NULL, 0, NULL, &context);
 
 	if (return_value == MA_SUCCESS)
 	{
-		return_value = ma_mutex_init(device.pContext, &mutex);
+		return_value = ma_device_init(&context, &config, &device);
 
 		if (return_value == MA_SUCCESS)
 		{
-			return_value = ma_mutex_init(device.pContext, &organya_mutex);
+			return_value = ma_mutex_init(device.pContext, &mutex);
 
 			if (return_value == MA_SUCCESS)
 			{
-				return_value = ma_device_start(&device);
+				return_value = ma_mutex_init(device.pContext, &organya_mutex);
 
 				if (return_value == MA_SUCCESS)
 				{
-					output_frequency = device.sampleRate;
+					return_value = ma_device_start(&device);
 
-					Mixer_Init(device.sampleRate);
+					if (return_value == MA_SUCCESS)
+					{
+						output_frequency = device.sampleRate;
 
-					return true;
+						Mixer_Init(device.sampleRate);
+
+						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 start playback device: %s", ma_result_description(return_value));
+					Backend_PrintError("Failed to create organya mutex: %s", ma_result_description(return_value));
 				}
 
-				ma_mutex_uninit(&organya_mutex);
+				ma_mutex_uninit(&mutex);
 			}
 			else
 			{
-				Backend_PrintError("Failed to create organya mutex: %s", ma_result_description(return_value));
+				Backend_PrintError("Failed to create mutex: %s", ma_result_description(return_value));
 			}
 
-			ma_mutex_uninit(&mutex);
+			ma_device_uninit(&device);
 		}
 		else
 		{
-			Backend_PrintError("Failed to create mutex: %s", ma_result_description(return_value));
+			Backend_PrintError("Failed to initialize playback device: %s", ma_result_description(return_value));
 		}
 
-		ma_device_uninit(&device);
+		ma_context_uninit(&context);
 	}
 	else
 	{
-		Backend_PrintError("Failed to initialize playback device: %s", ma_result_description(return_value));
+		Backend_PrintError("Failed to initialize context: %s", ma_result_description(return_value));
 	}
 
 
@@ -146,6 +157,8 @@
 	ma_mutex_uninit(&mutex);
 
 	ma_device_uninit(&device);
+
+	ma_context_uninit(&context);
 }
 
 AudioBackend_Sound* AudioBackend_CreateSound(unsigned int frequency, const unsigned char *samples, size_t length)