From 5578c285d866488d06f99f5e72e3fb9291d37eca Mon Sep 17 00:00:00 2001
From: Vadim ProductEngine <vsavchuk@productengine.com>
Date: Mon, 22 Aug 2011 14:01:18 +0300
Subject: [PATCH] STORM-1543 WIP More cleanup and comments.

---
 indra/newview/llappviewer.cpp     | 21 ++++++++-------------
 indra/newview/llviewermessage.cpp |  4 ++++
 2 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp
index 16c2b2d55a9..326b5fd629f 100644
--- a/indra/newview/llappviewer.cpp
+++ b/indra/newview/llappviewer.cpp
@@ -332,13 +332,11 @@ const char* const VIEWER_WINDOW_CLASSNAME = "Second Life";
  * Tasks added to this list will be executed in the next LLAppViewer::idle() iteration.
  * All tasks are executed only once.
  */
-class LLDeferredTaskList:
-	public LLSingleton<LLDeferredTaskList>,
-	private LLDestroyClass<LLDeferredTaskList>
+class LLDeferredTaskList: public LLSingleton<LLDeferredTaskList>
 {
 	LOG_CLASS(LLDeferredTaskList);
+
 	friend class LLAppViewer;
-	friend class LLDestroyClass<LLDeferredTaskList>;
 	typedef boost::signals2::signal<void()> signal_t;
 
 	void addTask(const signal_t::slot_type& cb)
@@ -348,15 +346,11 @@ class LLDeferredTaskList:
 
 	void run()
 	{
-		if (mSignal.empty()) return;
-
-		mSignal();
-		mSignal.disconnect_all_slots();
-	}
-
-	static void destroyClass()
-	{
-		instance().mSignal.disconnect_all_slots();
+		if (!mSignal.empty())
+		{
+			mSignal();
+			mSignal.disconnect_all_slots();
+		}
 	}
 
 	signal_t mSignal;
@@ -4460,6 +4454,7 @@ void LLAppViewer::idle()
 		}
 	}
 
+	// Execute deferred tasks.
 	LLDeferredTaskList::instance().run();
 	
 	// Handle shutdown process, for example, 
diff --git a/indra/newview/llviewermessage.cpp b/indra/newview/llviewermessage.cpp
index 22966015c82..793abb1c9d4 100644
--- a/indra/newview/llviewermessage.cpp
+++ b/indra/newview/llviewermessage.cpp
@@ -1060,6 +1060,10 @@ class LLDiscardAgentOffer : public LLInventoryFetchItemsObserver
 	{
 		LL_DEBUGS("Messaging") << "LLDiscardAgentOffer::done()" << LL_ENDL;
 
+		// We're invoked from LLInventoryModel::notifyObservers().
+		// If we now try to remove the inventory item, it will cause a nested
+		// notifyObservers() call, which won't work.
+		// So defer moving the item to trash until viewer gets idle (in a moment).
 		LLAppViewer::instance()->addOnIdleCallback(boost::bind(&LLInventoryModel::removeItem, &gInventory, mObjectID));
 		gInventory.removeObserver(this);
 		delete this;
-- 
GitLab