summaryrefslogtreecommitdiff
path: root/servers
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2017-09-17 22:48:22 +0200
committerGitHub <noreply@github.com>2017-09-17 22:48:22 +0200
commit53bbc046ee670a1c24b1ec936066857ef6e73dc9 (patch)
tree912835b1b1872785c0ffadda66d8996f5e7f9823 /servers
parenta00f19a92109ec33de41308e6277b55eb444320d (diff)
parent7a4c0ff35e10fba5f2686e7fd5623eab31b07a2d (diff)
Merge pull request #11252 from marcelofg55/fix_noaudio_crash
Fix crash when no audio driver is available
Diffstat (limited to 'servers')
-rw-r--r--servers/audio_server.cpp39
-rw-r--r--servers/audio_server.h5
2 files changed, 44 insertions, 0 deletions
diff --git a/servers/audio_server.cpp b/servers/audio_server.cpp
index 4b728f821a..78efe85e16 100644
--- a/servers/audio_server.cpp
+++ b/servers/audio_server.cpp
@@ -32,6 +32,7 @@
#include "os/file_access.h"
#include "os/os.h"
#include "project_settings.h"
+#include "servers/audio/audio_driver_dummy.h"
#include "servers/audio/effects/audio_effect_compressor.h"
#ifdef TOOLS_ENABLED
@@ -107,6 +108,7 @@ AudioDriver::AudioDriver() {
AudioDriver *AudioDriverManager::drivers[MAX_DRIVERS];
int AudioDriverManager::driver_count = 0;
+AudioDriverDummy AudioDriverManager::dummy_driver;
void AudioDriverManager::add_driver(AudioDriver *p_driver) {
@@ -118,6 +120,43 @@ int AudioDriverManager::get_driver_count() {
return driver_count;
}
+
+void AudioDriverManager::initialize(int p_driver) {
+ AudioDriver *driver;
+ int failed_driver = -1;
+
+ // Check if there is a selected driver
+ if (p_driver >= 0 && p_driver < driver_count) {
+ if (drivers[p_driver]->init() == OK) {
+ drivers[p_driver]->set_singleton();
+ return;
+ } else {
+ failed_driver = p_driver;
+ }
+ }
+
+ // No selected driver, try them all in order
+ for (int i = 0; i < driver_count; i++) {
+ // Don't re-init the driver if it failed above
+ if (i == failed_driver) {
+ continue;
+ }
+
+ if (drivers[i]->init() == OK) {
+ drivers[i]->set_singleton();
+ return;
+ }
+ }
+
+ // Fallback to our dummy driver
+ if (dummy_driver.init() == OK) {
+ ERR_PRINT("AudioDriverManager: all drivers failed, falling back to dummy driver");
+ dummy_driver.set_singleton();
+ } else {
+ ERR_PRINT("AudioDriverManager: dummy driver faild to init()");
+ }
+}
+
AudioDriver *AudioDriverManager::get_driver(int p_driver) {
ERR_FAIL_INDEX_V(p_driver, driver_count, NULL);
diff --git a/servers/audio_server.h b/servers/audio_server.h
index c479d09a3c..55e9367308 100644
--- a/servers/audio_server.h
+++ b/servers/audio_server.h
@@ -35,6 +35,8 @@
#include "servers/audio/audio_effect.h"
#include "variant.h"
+class AudioDriverDummy;
+
class AudioDriver {
static AudioDriver *singleton;
@@ -90,8 +92,11 @@ class AudioDriverManager {
static AudioDriver *drivers[MAX_DRIVERS];
static int driver_count;
+ static AudioDriverDummy dummy_driver;
+
public:
static void add_driver(AudioDriver *p_driver);
+ static void initialize(int p_driver);
static int get_driver_count();
static AudioDriver *get_driver(int p_driver);
};