diff --git a/es-app/src/main.cpp b/es-app/src/main.cpp index e61063807..9a5d1eff1 100644 --- a/es-app/src/main.cpp +++ b/es-app/src/main.cpp @@ -32,6 +32,7 @@ #include "MameNames.h" #include "Platform.h" #include "Settings.h" +#include "Sound.h" #include "SystemData.h" #include "SystemScreensaver.h" @@ -614,6 +615,7 @@ int main(int argc, char* argv[]) MameNames::deinit(); CollectionSystemsManager::deinit(); SystemData::deleteSystems(); + NavigationSounds::getInstance()->deinit(); // Call this ONLY when linking with FreeImage as a static library. #if defined(FREEIMAGE_LIB) diff --git a/es-core/src/AudioManager.cpp b/es-core/src/AudioManager.cpp index 8b091ccea..490b9d93a 100644 --- a/es-core/src/AudioManager.cpp +++ b/es-core/src/AudioManager.cpp @@ -235,7 +235,7 @@ void AudioManager::unregisterSound(std::shared_ptr& sound) return; } } - LOG(LogError) << "AudioManager - tried to unregister a sound that wasn't registered!"; + LOG(LogError) << "AudioManager - tried to unregister a sound that wasn't registered"; } void AudioManager::play() diff --git a/es-core/src/Sound.cpp b/es-core/src/Sound.cpp index 9368755d5..6ca48d8a4 100644 --- a/es-core/src/Sound.cpp +++ b/es-core/src/Sound.cpp @@ -60,7 +60,6 @@ Sound::Sound( Sound::~Sound() { - deinit(); } void Sound::loadFile(const std::string& path) @@ -137,6 +136,7 @@ void Sound::deinit() mSampleLength = 0; mSamplePos = 0; SDL_UnlockAudioDevice(AudioManager::sAudioDevice); + sMap.erase(mPath); } } @@ -214,21 +214,27 @@ NavigationSounds* NavigationSounds::getInstance() void NavigationSounds::deinit() { - if (sInstance) + if (sInstance) { + for (auto sound : navigationSounds) { + AudioManager::getInstance()->unregisterSound(sound); + sound->deinit(); + } + navigationSounds.clear(); delete sInstance; + } sInstance = nullptr; } void NavigationSounds::loadThemeNavigationSounds(const std::shared_ptr& theme) { - navigationSounds.push_back(Sound::getFromTheme(theme, "all", "systembrowse")); - navigationSounds.push_back(Sound::getFromTheme(theme, "all", "quicksysselect")); - navigationSounds.push_back(Sound::getFromTheme(theme, "all", "select")); - navigationSounds.push_back(Sound::getFromTheme(theme, "all", "back")); - navigationSounds.push_back(Sound::getFromTheme(theme, "all", "scroll")); - navigationSounds.push_back(Sound::getFromTheme(theme, "all", "favorite")); - navigationSounds.push_back(Sound::getFromTheme(theme, "all", "launch")); + navigationSounds.push_back(std::move(Sound::getFromTheme(theme, "all", "systembrowse"))); + navigationSounds.push_back(std::move(Sound::getFromTheme(theme, "all", "quicksysselect"))); + navigationSounds.push_back(std::move(Sound::getFromTheme(theme, "all", "select"))); + navigationSounds.push_back(std::move(Sound::getFromTheme(theme, "all", "back"))); + navigationSounds.push_back(std::move(Sound::getFromTheme(theme, "all", "scroll"))); + navigationSounds.push_back(std::move(Sound::getFromTheme(theme, "all", "favorite"))); + navigationSounds.push_back(std::move(Sound::getFromTheme(theme, "all", "launch"))); } void NavigationSounds::playThemeNavigationSound(NavigationSoundsID soundID)