1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

Don't crash when music file cannot be found.

This commit is contained in:
Michał W. Urbańczyk
2013-08-01 13:52:01 +00:00
parent 7a90ead051
commit f897333b2c
2 changed files with 20 additions and 7 deletions

View File

@@ -352,7 +352,7 @@ void CMusicHandler::playMusic(std::string musicURI, bool loop)
if (current && current->isTrack( musicURI)) if (current && current->isTrack( musicURI))
return; return;
queueNext(new MusicEntry(this, "", musicURI, loop)); queueNext(this, "", musicURI, loop);
} }
void CMusicHandler::playMusicFromSet(std::string whichSet, bool loop) void CMusicHandler::playMusicFromSet(std::string whichSet, bool loop)
@@ -367,7 +367,7 @@ void CMusicHandler::playMusicFromSet(std::string whichSet, bool loop)
if (current && current->isSet(whichSet)) if (current && current->isSet(whichSet))
return; return;
queueNext(new MusicEntry(this, whichSet, "", loop)); queueNext(this, whichSet, "", loop);
} }
@@ -390,17 +390,16 @@ void CMusicHandler::playMusicFromSet(std::string whichSet, int entryID, bool loo
if (current && current->isTrack( selectedEntry->second)) if (current && current->isTrack( selectedEntry->second))
return; return;
queueNext(new MusicEntry(this, "", selectedEntry->second, loop));
} }
void CMusicHandler::queueNext(MusicEntry *queued) void CMusicHandler::queueNext(unique_ptr<MusicEntry> queued)
{ {
if (!initialized) if (!initialized)
return; return;
boost::mutex::scoped_lock guard(musicMutex); boost::mutex::scoped_lock guard(musicMutex);
next.reset(queued); next = std::move(queued);
if (current.get() == nullptr || !current->stop(1000)) if (current.get() == nullptr || !current->stop(1000))
{ {
@@ -409,6 +408,19 @@ void CMusicHandler::queueNext(MusicEntry *queued)
} }
} }
void CMusicHandler::queueNext(CMusicHandler *owner, std::string setName, std::string musicURI, bool looped)
{
try
{
queueNext(make_unique<MusicEntry>(owner, setName, musicURI, looped));
}
catch(std::exception &e)
{
logGlobal->errorStream() << "Failed to queue music. setName=" << setName << "\tmusicURI=" << musicURI;
logGlobal->errorStream() << "Exception: " << e.what();
}
}
void CMusicHandler::stopMusic(int fade_ms) void CMusicHandler::stopMusic(int fade_ms)
{ {
if (!initialized) if (!initialized)

View File

@@ -120,8 +120,9 @@ private:
unique_ptr<MusicEntry> current; unique_ptr<MusicEntry> current;
unique_ptr<MusicEntry> next; unique_ptr<MusicEntry> next;
void queueNext(MusicEntry *queued); void queueNext(CMusicHandler *owner, std::string setName, std::string musicURI, bool looped);
void queueNext(unique_ptr<MusicEntry> queued);
std::map<std::string, std::map<int, std::string> > musicsSet; std::map<std::string, std::map<int, std::string> > musicsSet;
public: public: