summaryrefslogtreecommitdiff
path: root/src/soundmanager.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-05-24 04:29:03 +0300
committerAndrei Karas <akaras@inbox.ru>2016-05-24 04:29:03 +0300
commit9ba40776e3b0b00235e821c1157c6b4e0245417d (patch)
tree1934b95a1c73818d9e6f6d77d04b8daa8ef79e59 /src/soundmanager.cpp
parent3e5dbaaa903d4f4ea039902ab83259cb1e11a2f4 (diff)
downloadmv-9ba40776e3b0b00235e821c1157c6b4e0245417d.tar.gz
mv-9ba40776e3b0b00235e821c1157c6b4e0245417d.tar.bz2
mv-9ba40776e3b0b00235e821c1157c6b4e0245417d.tar.xz
mv-9ba40776e3b0b00235e821c1157c6b4e0245417d.zip
Fix asserts with missing default music files.
Diffstat (limited to 'src/soundmanager.cpp')
-rw-r--r--src/soundmanager.cpp27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/soundmanager.cpp b/src/soundmanager.cpp
index 42a642188..45490d497 100644
--- a/src/soundmanager.cpp
+++ b/src/soundmanager.cpp
@@ -33,6 +33,9 @@
#include "resources/resourcemanager.h"
#include "resources/soundeffect.h"
+#include "utils/checkutils.h"
+#include "utils/physfstools.h"
+
#include <SDL.h>
#include "debug.h"
@@ -172,7 +175,7 @@ void SoundManager::init()
mInstalled = true;
if (!mCurrentMusicFile.empty() && mPlayMusic)
- playMusic(mCurrentMusicFile);
+ playMusic(mCurrentMusicFile, SkipError_true);
}
void SoundManager::testAudio()
@@ -316,13 +319,21 @@ void SoundManager::setSfxVolume(const int volume)
Mix_Volume(-1, mSfxVolume);
}
-static SDLMusic *loadMusic(const std::string &fileName)
+static SDLMusic *loadMusic(const std::string &fileName,
+ const SkipError skipError)
{
- return resourceManager->getMusic(
- paths.getStringValue("music").append(fileName));
+ const std::string path = paths.getStringValue("music").append(fileName);
+ if (!PhysFs::exists(path.c_str()))
+ {
+ if (skipError == SkipError_false)
+ reportAlways("Music file not found: %s", fileName.c_str());
+ return nullptr;
+ }
+ return resourceManager->getMusic(path);
}
-void SoundManager::playMusic(const std::string &fileName)
+void SoundManager::playMusic(const std::string &fileName,
+ const SkipError skipError)
{
if (!mInstalled || !mPlayMusic)
return;
@@ -336,7 +347,8 @@ void SoundManager::playMusic(const std::string &fileName)
if (!fileName.empty())
{
- mMusic = loadMusic(fileName);
+ mMusic = loadMusic(fileName,
+ skipError);
if (mMusic)
mMusic->play();
}
@@ -416,7 +428,8 @@ void SoundManager::logic()
if (!mNextMusicFile.empty())
{
- playMusic(mNextMusicFile);
+ playMusic(mNextMusicFile,
+ SkipError_false);
mNextMusicFile.clear();
}
}