From 8056a7f20b22d57c77a9cb42addcad84da022672 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 21 Mar 2012 18:20:32 -0700 Subject: [PATCH] Throw an exception when looking up a sound instead of returning an empty string --- apps/openmw/mwsound/soundmanager.cpp | 39 ++++++++++++++-------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/apps/openmw/mwsound/soundmanager.cpp b/apps/openmw/mwsound/soundmanager.cpp index 5a6b07e0a8..cce1bfefe9 100644 --- a/apps/openmw/mwsound/soundmanager.cpp +++ b/apps/openmw/mwsound/soundmanager.cpp @@ -86,7 +86,8 @@ namespace MWSound float &volume, float &min, float &max) { const ESM::Sound *snd = mEnvironment.mWorld->getStore().sounds.search(soundId); - if(snd == NULL) return ""; + if(snd == NULL) + throw std::runtime_error(std::string("Failed to lookup sound ")+soundId); if(snd->data.volume == 0) volume = 0.0f; @@ -224,34 +225,32 @@ namespace MWSound void SoundManager::playSound(const std::string& soundId, float volume, float pitch, bool loop) { float min, max; - std::string file = lookup(soundId, volume, min, max); - if(!file.empty()) + try { - try - { - Sound *sound; - sound = mOutput->playSound(file, volume, pitch, loop); - mLooseSounds[soundId] = SoundPtr(sound); - } - catch(std::exception &e) - { - std::cout <<"Sound play error: "<playSound(file, volume, pitch, loop); + mLooseSounds[soundId] = SoundPtr(sound); + } + catch(std::exception &e) + { + std::cout <<"Sound play error: "<