瀏覽代碼

Don't crash when music file cannot be found.

Michał W. Urbańczyk 12 年之前
父節點
當前提交
f897333b2c
共有 2 個文件被更改,包括 20 次插入7 次删除
  1. 17 5
      client/CMusicHandler.cpp
  2. 3 2
      client/CMusicHandler.h

+ 17 - 5
client/CMusicHandler.cpp

@@ -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)

+ 3 - 2
client/CMusicHandler.h

@@ -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: