mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-25 21:38:59 +02:00
Don't crash when music file cannot be found.
This commit is contained in:
parent
7a90ead051
commit
f897333b2c
@ -352,7 +352,7 @@ void CMusicHandler::playMusic(std::string musicURI, bool loop)
|
||||
if (current && current->isTrack( musicURI))
|
||||
return;
|
||||
|
||||
queueNext(new MusicEntry(this, "", musicURI, loop));
|
||||
queueNext(this, "", musicURI, 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))
|
||||
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))
|
||||
return;
|
||||
|
||||
queueNext(new MusicEntry(this, "", selectedEntry->second, loop));
|
||||
}
|
||||
|
||||
void CMusicHandler::queueNext(MusicEntry *queued)
|
||||
void CMusicHandler::queueNext(unique_ptr<MusicEntry> queued)
|
||||
{
|
||||
if (!initialized)
|
||||
return;
|
||||
|
||||
boost::mutex::scoped_lock guard(musicMutex);
|
||||
|
||||
next.reset(queued);
|
||||
next = std::move(queued);
|
||||
|
||||
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)
|
||||
{
|
||||
if (!initialized)
|
||||
|
@ -120,8 +120,9 @@ private:
|
||||
|
||||
unique_ptr<MusicEntry> current;
|
||||
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;
|
||||
public:
|
||||
|
Loading…
x
Reference in New Issue
Block a user