diff --git a/src/RageSoundManager.cpp b/src/RageSoundManager.cpp index 6e0c248363..cc42687041 100644 --- a/src/RageSoundManager.cpp +++ b/src/RageSoundManager.cpp @@ -55,6 +55,11 @@ RageSoundManager::~RageSoundManager() m_mapPreloadedSounds.clear(); } +void RageSoundManager::fix_bogus_sound_driver_pref(RString const& valid_setting) +{ + g_sSoundDrivers.Set(valid_setting); +} + /* * Previously, we went to some lengths to shut down sounds before exiting threads. * The only other thread that actually starts sounds is SOUND. Doing this was ugly; diff --git a/src/RageSoundManager.h b/src/RageSoundManager.h index 541f96e400..f6db421e74 100644 --- a/src/RageSoundManager.h +++ b/src/RageSoundManager.h @@ -45,6 +45,8 @@ public: RageSoundReader *GetLoadedSound( const RString &sPath ); void AddLoadedSound( const RString &sPath, RageSoundReader_Preload *pSound ); + void fix_bogus_sound_driver_pref(RString const& valid_setting); + private: map m_mapPreloadedSounds; diff --git a/src/arch/Sound/RageSoundDriver.cpp b/src/arch/Sound/RageSoundDriver.cpp index 52f273422a..b809c5ac04 100644 --- a/src/arch/Sound/RageSoundDriver.cpp +++ b/src/arch/Sound/RageSoundDriver.cpp @@ -1,5 +1,6 @@ #include "global.h" #include "RageSoundDriver.h" +#include "RageSoundManager.h" #include "RageLog.h" #include "RageUtil.h" #include "Foreach.h" @@ -7,12 +8,44 @@ DriverList RageSoundDriver::m_pDriverList; -RageSoundDriver *RageSoundDriver::Create( const RString& sDrivers ) +RageSoundDriver *RageSoundDriver::Create( const RString& drivers ) { - vector DriversToTry; - split( sDrivers.empty()? DEFAULT_SOUND_DRIVER_LIST:sDrivers, ",", DriversToTry, true ); - - FOREACH_CONST( RString, DriversToTry, Driver ) + vector drivers_to_try; + if(drivers.empty()) + { + split(DEFAULT_SOUND_DRIVER_LIST, ",", drivers_to_try); + } + else + { + split(drivers, ",", drivers_to_try); + vector default_drivers; + split(DEFAULT_SOUND_DRIVER_LIST, ",", default_drivers); + size_t to_try= 0; + bool had_to_erase= false; + while(to_try < drivers_to_try.size()) + { + if(std::find(default_drivers.begin(), default_drivers.end(), drivers_to_try[to_try]) == default_drivers.end()) + { + LOG->Warn("Removed unusable sound driver %s", drivers_to_try[to_try].c_str()); + drivers_to_try.erase(drivers_to_try.begin() + to_try); + had_to_erase= true; + } + else + { + ++to_try; + } + } + if(had_to_erase) + { + SOUNDMAN->fix_bogus_sound_driver_pref(join(",", drivers_to_try)); + } + if(drivers_to_try.empty()) + { + split(DEFAULT_SOUND_DRIVER_LIST, ",", drivers_to_try); + } + } + + FOREACH_CONST( RString, drivers_to_try, Driver ) { RageDriver *pDriver = m_pDriverList.Create( *Driver ); if( pDriver == NULL )