From 8b767a1189f974d290ce90bf433d762a18da8961 Mon Sep 17 00:00:00 2001 From: Moncef Mechri Date: Sun, 9 Aug 2015 23:06:26 +0200 Subject: [PATCH] Use dummy audio backend if the selected backend fails to start If the selected audio backend fails to Start() (which could happen for example if there is no audio device), we currently still use the backend anyway. This can lead to crashes on some platforms (such as Windows) and is outright wrong anyway. This commit fallbacks to the Null audio backend if the selected backend couldn't be started. This fixes bug #6001 --- Source/Core/AudioCommon/AudioCommon.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Source/Core/AudioCommon/AudioCommon.cpp b/Source/Core/AudioCommon/AudioCommon.cpp index f5438faca9..19b6cc0e89 100644 --- a/Source/Core/AudioCommon/AudioCommon.cpp +++ b/Source/Core/AudioCommon/AudioCommon.cpp @@ -65,14 +65,19 @@ namespace AudioCommon if (g_sound_stream) { UpdateSoundStream(); - if (g_sound_stream->Start()) + if (!g_sound_stream->Start()) { - if (SConfig::GetInstance().m_DumpAudio && !s_audio_dump_start) - StartAudioDump(); - - return g_sound_stream; + ERROR_LOG(AUDIO, "Could not start backend %s, using %s instead", + backend.c_str(), BACKEND_NULLSOUND); + delete g_sound_stream; + g_sound_stream = new NullSound(); + g_sound_stream->Start(); } - PanicAlertT("Could not initialize backend %s.", backend.c_str()); + + if (SConfig::GetInstance().m_DumpAudio && !s_audio_dump_start) + StartAudioDump(); + + return g_sound_stream; } PanicAlertT("Sound backend %s is not valid.", backend.c_str());