Fix crash when no audio driver is available
This commit is contained in:
parent
d6b392825f
commit
7a4c0ff35e
@ -143,7 +143,7 @@ Error AudioDriverRtAudio::init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return OK;
|
return active ? OK : ERR_UNAVAILABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int AudioDriverRtAudio::get_mix_rate() const {
|
int AudioDriverRtAudio::get_mix_rate() const {
|
||||||
|
@ -137,12 +137,7 @@ void OS_Android::initialize(const VideoMode &p_desired, int p_video_driver, int
|
|||||||
visual_server->init();
|
visual_server->init();
|
||||||
// visual_server->cursor_set_visible(false, 0);
|
// visual_server->cursor_set_visible(false, 0);
|
||||||
|
|
||||||
AudioDriverManager::get_driver(p_audio_driver)->set_singleton();
|
AudioDriverManager::initialize(p_audio_driver);
|
||||||
|
|
||||||
if (AudioDriverManager::get_driver(p_audio_driver)->init() != OK) {
|
|
||||||
|
|
||||||
ERR_PRINT("Initializing audio failed.");
|
|
||||||
}
|
|
||||||
|
|
||||||
physics_server = memnew(PhysicsServerSW);
|
physics_server = memnew(PhysicsServerSW);
|
||||||
physics_server->init();
|
physics_server->init();
|
||||||
|
@ -137,11 +137,7 @@ void OS_Haiku::initialize(const VideoMode &p_desired, int p_video_driver, int p_
|
|||||||
//physics_2d_server = Physics2DServerWrapMT::init_server<Physics2DServerSW>();
|
//physics_2d_server = Physics2DServerWrapMT::init_server<Physics2DServerSW>();
|
||||||
physics_2d_server->init();
|
physics_2d_server->init();
|
||||||
|
|
||||||
AudioDriverManager::get_driver(p_audio_driver)->set_singleton();
|
AudioDriverManager::initialize(p_audio_driver);
|
||||||
|
|
||||||
if (AudioDriverManager::get_driver(p_audio_driver)->init() != OK) {
|
|
||||||
ERR_PRINT("Initializing audio failed.");
|
|
||||||
}
|
|
||||||
|
|
||||||
power_manager = memnew(PowerHaiku);
|
power_manager = memnew(PowerHaiku);
|
||||||
}
|
}
|
||||||
|
@ -464,11 +464,7 @@ void OS_JavaScript::initialize(const VideoMode &p_desired, int p_video_driver, i
|
|||||||
print_line("Init Audio");
|
print_line("Init Audio");
|
||||||
|
|
||||||
AudioDriverManager::add_driver(&audio_driver_javascript);
|
AudioDriverManager::add_driver(&audio_driver_javascript);
|
||||||
audio_driver_javascript.set_singleton();
|
AudioDriverManager::initialize(p_audio_driver);
|
||||||
if (audio_driver_javascript.init() != OK) {
|
|
||||||
|
|
||||||
ERR_PRINT("Initializing audio failed.");
|
|
||||||
}
|
|
||||||
|
|
||||||
RasterizerGLES3::register_config();
|
RasterizerGLES3::register_config();
|
||||||
RasterizerGLES3::make_current();
|
RasterizerGLES3::make_current();
|
||||||
|
@ -1088,12 +1088,7 @@ void OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_au
|
|||||||
visual_server->init();
|
visual_server->init();
|
||||||
// visual_server->cursor_set_visible(false, 0);
|
// visual_server->cursor_set_visible(false, 0);
|
||||||
|
|
||||||
AudioDriverManager::get_driver(p_audio_driver)->set_singleton();
|
AudioDriverManager::initialize(p_audio_driver);
|
||||||
|
|
||||||
if (AudioDriverManager::get_driver(p_audio_driver)->init() != OK) {
|
|
||||||
|
|
||||||
ERR_PRINT("Initializing audio failed.");
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
physics_server = memnew(PhysicsServerSW);
|
physics_server = memnew(PhysicsServerSW);
|
||||||
|
@ -62,12 +62,7 @@ void OS_Server::initialize(const VideoMode &p_desired, int p_video_driver, int p
|
|||||||
|
|
||||||
//visual_server = memnew( VisualServerRaster(rasterizer) );
|
//visual_server = memnew( VisualServerRaster(rasterizer) );
|
||||||
|
|
||||||
AudioDriverManager::get_driver(p_audio_driver)->set_singleton();
|
AudioDriverManager::initialize(p_audio_driver);
|
||||||
|
|
||||||
if (AudioDriverManager::get_driver(p_audio_driver)->init() != OK) {
|
|
||||||
|
|
||||||
ERR_PRINT("Initializing audio failed.");
|
|
||||||
}
|
|
||||||
|
|
||||||
sample_manager = memnew(SampleManagerMallocSW);
|
sample_manager = memnew(SampleManagerMallocSW);
|
||||||
audio_server = memnew(AudioServerSW(sample_manager));
|
audio_server = memnew(AudioServerSW(sample_manager));
|
||||||
@ -232,7 +227,6 @@ void OS_Server::run() {
|
|||||||
|
|
||||||
OS_Server::OS_Server() {
|
OS_Server::OS_Server() {
|
||||||
|
|
||||||
AudioDriverManager::add_driver(&driver_dummy);
|
|
||||||
//adriver here
|
//adriver here
|
||||||
grab = false;
|
grab = false;
|
||||||
};
|
};
|
||||||
|
@ -34,7 +34,6 @@
|
|||||||
#include "drivers/rtaudio/audio_driver_rtaudio.h"
|
#include "drivers/rtaudio/audio_driver_rtaudio.h"
|
||||||
#include "drivers/unix/os_unix.h"
|
#include "drivers/unix/os_unix.h"
|
||||||
#include "main/input_default.h"
|
#include "main/input_default.h"
|
||||||
#include "servers/audio/audio_driver_dummy.h"
|
|
||||||
#include "servers/audio_server.h"
|
#include "servers/audio_server.h"
|
||||||
#include "servers/physics_2d/physics_2d_server_sw.h"
|
#include "servers/physics_2d/physics_2d_server_sw.h"
|
||||||
#include "servers/physics_server.h"
|
#include "servers/physics_server.h"
|
||||||
@ -55,7 +54,6 @@ class OS_Server : public OS_Unix {
|
|||||||
List<String> args;
|
List<String> args;
|
||||||
MainLoop *main_loop;
|
MainLoop *main_loop;
|
||||||
|
|
||||||
AudioDriverDummy driver_dummy;
|
|
||||||
bool grab;
|
bool grab;
|
||||||
|
|
||||||
PhysicsServer *physics_server;
|
PhysicsServer *physics_server;
|
||||||
|
@ -268,12 +268,7 @@ void OSUWP::initialize(const VideoMode &p_desired, int p_video_driver, int p_aud
|
|||||||
joypad = ref new JoypadUWP(input);
|
joypad = ref new JoypadUWP(input);
|
||||||
joypad->register_events();
|
joypad->register_events();
|
||||||
|
|
||||||
AudioDriverManager::get_driver(p_audio_driver)->set_singleton();
|
AudioDriverManager::initialize(p_audio_driver);
|
||||||
|
|
||||||
if (AudioDriverManager::get_driver(p_audio_driver)->init() != OK) {
|
|
||||||
|
|
||||||
ERR_PRINT("Initializing audio failed.");
|
|
||||||
}
|
|
||||||
|
|
||||||
power_manager = memnew(PowerUWP);
|
power_manager = memnew(PowerUWP);
|
||||||
|
|
||||||
|
@ -1081,12 +1081,7 @@ void OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int
|
|||||||
|
|
||||||
power_manager = memnew(PowerWindows);
|
power_manager = memnew(PowerWindows);
|
||||||
|
|
||||||
AudioDriverManager::get_driver(p_audio_driver)->set_singleton();
|
AudioDriverManager::initialize(p_audio_driver);
|
||||||
|
|
||||||
if (AudioDriverManager::get_driver(p_audio_driver)->init() != OK) {
|
|
||||||
|
|
||||||
ERR_PRINT("Initializing audio failed.");
|
|
||||||
}
|
|
||||||
|
|
||||||
TRACKMOUSEEVENT tme;
|
TRACKMOUSEEVENT tme;
|
||||||
tme.cbSize = sizeof(TRACKMOUSEEVENT);
|
tme.cbSize = sizeof(TRACKMOUSEEVENT);
|
||||||
|
@ -313,29 +313,7 @@ void OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_au
|
|||||||
XFree(xsh);
|
XFree(xsh);
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioDriverManager::get_driver(p_audio_driver)->set_singleton();
|
AudioDriverManager::initialize(p_audio_driver);
|
||||||
|
|
||||||
audio_driver_index = p_audio_driver;
|
|
||||||
if (AudioDriverManager::get_driver(p_audio_driver)->init() != OK) {
|
|
||||||
|
|
||||||
bool success = false;
|
|
||||||
audio_driver_index = -1;
|
|
||||||
for (int i = 0; i < AudioDriverManager::get_driver_count(); i++) {
|
|
||||||
if (i == p_audio_driver)
|
|
||||||
continue;
|
|
||||||
AudioDriverManager::get_driver(i)->set_singleton();
|
|
||||||
if (AudioDriverManager::get_driver(i)->init() == OK) {
|
|
||||||
success = true;
|
|
||||||
print_line("Audio Driver Failed: " + String(AudioDriverManager::get_driver(p_audio_driver)->get_name()));
|
|
||||||
print_line("Using alternate audio driver: " + String(AudioDriverManager::get_driver(i)->get_name()));
|
|
||||||
audio_driver_index = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!success) {
|
|
||||||
ERR_PRINT("Initializing audio failed.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ERR_FAIL_COND(!visual_server);
|
ERR_FAIL_COND(!visual_server);
|
||||||
ERR_FAIL_COND(x11_window == 0);
|
ERR_FAIL_COND(x11_window == 0);
|
||||||
@ -2189,10 +2167,6 @@ bool OS_X11::is_disable_crash_handler() const {
|
|||||||
|
|
||||||
OS_X11::OS_X11() {
|
OS_X11::OS_X11() {
|
||||||
|
|
||||||
#ifdef RTAUDIO_ENABLED
|
|
||||||
AudioDriverManager::add_driver(&driver_rtaudio);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef PULSEAUDIO_ENABLED
|
#ifdef PULSEAUDIO_ENABLED
|
||||||
AudioDriverManager::add_driver(&driver_pulseaudio);
|
AudioDriverManager::add_driver(&driver_pulseaudio);
|
||||||
#endif
|
#endif
|
||||||
@ -2201,11 +2175,6 @@ OS_X11::OS_X11() {
|
|||||||
AudioDriverManager::add_driver(&driver_alsa);
|
AudioDriverManager::add_driver(&driver_alsa);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (AudioDriverManager::get_driver_count() == 0) {
|
|
||||||
WARN_PRINT("No sound driver found... Defaulting to dummy driver");
|
|
||||||
AudioDriverManager::add_driver(&driver_dummy);
|
|
||||||
}
|
|
||||||
|
|
||||||
minimized = false;
|
minimized = false;
|
||||||
xim_style = 0L;
|
xim_style = 0L;
|
||||||
mouse_mode = MOUSE_MODE_VISIBLE;
|
mouse_mode = MOUSE_MODE_VISIBLE;
|
||||||
|
@ -38,11 +38,9 @@
|
|||||||
//#include "servers/visual/visual_server_wrap_mt.h"
|
//#include "servers/visual/visual_server_wrap_mt.h"
|
||||||
#include "drivers/alsa/audio_driver_alsa.h"
|
#include "drivers/alsa/audio_driver_alsa.h"
|
||||||
#include "drivers/pulseaudio/audio_driver_pulseaudio.h"
|
#include "drivers/pulseaudio/audio_driver_pulseaudio.h"
|
||||||
#include "drivers/rtaudio/audio_driver_rtaudio.h"
|
|
||||||
#include "joypad_linux.h"
|
#include "joypad_linux.h"
|
||||||
#include "main/input_default.h"
|
#include "main/input_default.h"
|
||||||
#include "power_x11.h"
|
#include "power_x11.h"
|
||||||
#include "servers/audio/audio_driver_dummy.h"
|
|
||||||
#include "servers/audio_server.h"
|
#include "servers/audio_server.h"
|
||||||
#include "servers/physics_2d/physics_2d_server_sw.h"
|
#include "servers/physics_2d/physics_2d_server_sw.h"
|
||||||
#include "servers/physics_2d/physics_2d_server_wrap_mt.h"
|
#include "servers/physics_2d/physics_2d_server_wrap_mt.h"
|
||||||
@ -154,10 +152,6 @@ class OS_X11 : public OS_Unix {
|
|||||||
JoypadLinux *joypad;
|
JoypadLinux *joypad;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef RTAUDIO_ENABLED
|
|
||||||
AudioDriverRtAudio driver_rtaudio;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef ALSA_ENABLED
|
#ifdef ALSA_ENABLED
|
||||||
AudioDriverALSA driver_alsa;
|
AudioDriverALSA driver_alsa;
|
||||||
#endif
|
#endif
|
||||||
@ -165,7 +159,6 @@ class OS_X11 : public OS_Unix {
|
|||||||
#ifdef PULSEAUDIO_ENABLED
|
#ifdef PULSEAUDIO_ENABLED
|
||||||
AudioDriverPulseAudio driver_pulseaudio;
|
AudioDriverPulseAudio driver_pulseaudio;
|
||||||
#endif
|
#endif
|
||||||
AudioDriverDummy driver_dummy;
|
|
||||||
|
|
||||||
Atom net_wm_icon;
|
Atom net_wm_icon;
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include "os/file_access.h"
|
#include "os/file_access.h"
|
||||||
#include "os/os.h"
|
#include "os/os.h"
|
||||||
#include "project_settings.h"
|
#include "project_settings.h"
|
||||||
|
#include "servers/audio/audio_driver_dummy.h"
|
||||||
#include "servers/audio/effects/audio_effect_compressor.h"
|
#include "servers/audio/effects/audio_effect_compressor.h"
|
||||||
#ifdef TOOLS_ENABLED
|
#ifdef TOOLS_ENABLED
|
||||||
|
|
||||||
@ -107,6 +108,7 @@ AudioDriver::AudioDriver() {
|
|||||||
|
|
||||||
AudioDriver *AudioDriverManager::drivers[MAX_DRIVERS];
|
AudioDriver *AudioDriverManager::drivers[MAX_DRIVERS];
|
||||||
int AudioDriverManager::driver_count = 0;
|
int AudioDriverManager::driver_count = 0;
|
||||||
|
AudioDriverDummy AudioDriverManager::dummy_driver;
|
||||||
|
|
||||||
void AudioDriverManager::add_driver(AudioDriver *p_driver) {
|
void AudioDriverManager::add_driver(AudioDriver *p_driver) {
|
||||||
|
|
||||||
@ -118,6 +120,43 @@ int AudioDriverManager::get_driver_count() {
|
|||||||
|
|
||||||
return 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) {
|
AudioDriver *AudioDriverManager::get_driver(int p_driver) {
|
||||||
|
|
||||||
ERR_FAIL_INDEX_V(p_driver, driver_count, NULL);
|
ERR_FAIL_INDEX_V(p_driver, driver_count, NULL);
|
||||||
|
@ -35,6 +35,8 @@
|
|||||||
#include "servers/audio/audio_effect.h"
|
#include "servers/audio/audio_effect.h"
|
||||||
#include "variant.h"
|
#include "variant.h"
|
||||||
|
|
||||||
|
class AudioDriverDummy;
|
||||||
|
|
||||||
class AudioDriver {
|
class AudioDriver {
|
||||||
|
|
||||||
static AudioDriver *singleton;
|
static AudioDriver *singleton;
|
||||||
@ -90,8 +92,11 @@ class AudioDriverManager {
|
|||||||
static AudioDriver *drivers[MAX_DRIVERS];
|
static AudioDriver *drivers[MAX_DRIVERS];
|
||||||
static int driver_count;
|
static int driver_count;
|
||||||
|
|
||||||
|
static AudioDriverDummy dummy_driver;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void add_driver(AudioDriver *p_driver);
|
static void add_driver(AudioDriver *p_driver);
|
||||||
|
static void initialize(int p_driver);
|
||||||
static int get_driver_count();
|
static int get_driver_count();
|
||||||
static AudioDriver *get_driver(int p_driver);
|
static AudioDriver *get_driver(int p_driver);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user