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
This commit is contained in:
Moncef Mechri 2015-08-09 23:06:26 +02:00
parent 697f55bc32
commit 8b767a1189
1 changed files with 11 additions and 6 deletions

View File

@ -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());