From ccabc6f1d8e994b095842dd5219f0a66ed2de519 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timmy=20Sj=C3=B6stedt?= Date: Sat, 28 May 2016 02:21:02 +0200 Subject: [PATCH] Improved music map access --- rwengine/src/audio/SoundManager.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/rwengine/src/audio/SoundManager.cpp b/rwengine/src/audio/SoundManager.cpp index 46b73720..3f4fe348 100644 --- a/rwengine/src/audio/SoundManager.cpp +++ b/rwengine/src/audio/SoundManager.cpp @@ -134,16 +134,22 @@ bool SoundManager::playBackground(const std::string& fileName) bool SoundManager::loadMusic(const std::string& name, const std::string& fileName) { - musics.emplace(std::piecewise_construct, std::forward_as_tuple(name), std::forward_as_tuple()); - return musics[name].openFromFile(fileName); + auto music = musics.emplace(std::piecewise_construct, std::forward_as_tuple(name), std::forward_as_tuple()); + return music.first->second.openFromFile(fileName); } void SoundManager::playMusic(const std::string& name) { - musics[name].play(); + auto music = musics.find(name); + if (music != musics.end()) { + music->second.play(); + } } void SoundManager::stopMusic(const std::string& name) { - musics[name].stop(); + auto music = musics.find(name); + if (music != musics.end()) { + music->second.stop(); + } } void SoundManager::pause(bool p)