Fixed a memory leak related to the navigation sounds.

This commit is contained in:
Leon Styhre 2021-03-19 18:37:56 +01:00
parent 08e6f1b0dd
commit b90ab39cb7
3 changed files with 18 additions and 10 deletions

View file

@ -32,6 +32,7 @@
#include "MameNames.h" #include "MameNames.h"
#include "Platform.h" #include "Platform.h"
#include "Settings.h" #include "Settings.h"
#include "Sound.h"
#include "SystemData.h" #include "SystemData.h"
#include "SystemScreensaver.h" #include "SystemScreensaver.h"
@ -614,6 +615,7 @@ int main(int argc, char* argv[])
MameNames::deinit(); MameNames::deinit();
CollectionSystemsManager::deinit(); CollectionSystemsManager::deinit();
SystemData::deleteSystems(); SystemData::deleteSystems();
NavigationSounds::getInstance()->deinit();
// Call this ONLY when linking with FreeImage as a static library. // Call this ONLY when linking with FreeImage as a static library.
#if defined(FREEIMAGE_LIB) #if defined(FREEIMAGE_LIB)

View file

@ -235,7 +235,7 @@ void AudioManager::unregisterSound(std::shared_ptr<Sound>& sound)
return; 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() void AudioManager::play()

View file

@ -60,7 +60,6 @@ Sound::Sound(
Sound::~Sound() Sound::~Sound()
{ {
deinit();
} }
void Sound::loadFile(const std::string& path) void Sound::loadFile(const std::string& path)
@ -137,6 +136,7 @@ void Sound::deinit()
mSampleLength = 0; mSampleLength = 0;
mSamplePos = 0; mSamplePos = 0;
SDL_UnlockAudioDevice(AudioManager::sAudioDevice); SDL_UnlockAudioDevice(AudioManager::sAudioDevice);
sMap.erase(mPath);
} }
} }
@ -214,21 +214,27 @@ NavigationSounds* NavigationSounds::getInstance()
void NavigationSounds::deinit() void NavigationSounds::deinit()
{ {
if (sInstance) if (sInstance) {
for (auto sound : navigationSounds) {
AudioManager::getInstance()->unregisterSound(sound);
sound->deinit();
}
navigationSounds.clear();
delete sInstance; delete sInstance;
}
sInstance = nullptr; sInstance = nullptr;
} }
void NavigationSounds::loadThemeNavigationSounds(const std::shared_ptr<ThemeData>& theme) void NavigationSounds::loadThemeNavigationSounds(const std::shared_ptr<ThemeData>& theme)
{ {
navigationSounds.push_back(Sound::getFromTheme(theme, "all", "systembrowse")); navigationSounds.push_back(std::move(Sound::getFromTheme(theme, "all", "systembrowse")));
navigationSounds.push_back(Sound::getFromTheme(theme, "all", "quicksysselect")); navigationSounds.push_back(std::move(Sound::getFromTheme(theme, "all", "quicksysselect")));
navigationSounds.push_back(Sound::getFromTheme(theme, "all", "select")); navigationSounds.push_back(std::move(Sound::getFromTheme(theme, "all", "select")));
navigationSounds.push_back(Sound::getFromTheme(theme, "all", "back")); navigationSounds.push_back(std::move(Sound::getFromTheme(theme, "all", "back")));
navigationSounds.push_back(Sound::getFromTheme(theme, "all", "scroll")); navigationSounds.push_back(std::move(Sound::getFromTheme(theme, "all", "scroll")));
navigationSounds.push_back(Sound::getFromTheme(theme, "all", "favorite")); navigationSounds.push_back(std::move(Sound::getFromTheme(theme, "all", "favorite")));
navigationSounds.push_back(Sound::getFromTheme(theme, "all", "launch")); navigationSounds.push_back(std::move(Sound::getFromTheme(theme, "all", "launch")));
} }
void NavigationSounds::playThemeNavigationSound(NavigationSoundsID soundID) void NavigationSounds::playThemeNavigationSound(NavigationSoundsID soundID)