From 23acc30e2709dac1aa54eecda5c1bc6b2b226b5b Mon Sep 17 00:00:00 2001
From: Merov Linden <merov@lindenlab.com>
Date: Fri, 16 May 2014 17:12:22 -0700
Subject: DD-102 : Fix crash when emptying trash containing nested folders.
 Also avoid getting listings several times

---
 indra/llui/llfolderviewitem.cpp                |  2 ++
 indra/newview/llfloatermarketplacelistings.cpp | 19 ++++---------------
 indra/newview/llinventorymodel.cpp             |  7 +++++--
 3 files changed, 11 insertions(+), 17 deletions(-)

diff --git a/indra/llui/llfolderviewitem.cpp b/indra/llui/llfolderviewitem.cpp
index aa2343226c..3455f970cd 100644
--- a/indra/llui/llfolderviewitem.cpp
+++ b/indra/llui/llfolderviewitem.cpp
@@ -1477,12 +1477,14 @@ void LLFolderViewFolder::destroyView()
     while (!mItems.empty())
     {
     	LLFolderViewItem *itemp = mItems.back();
+        mItems.pop_back();
     	itemp->destroyView(); // LLFolderViewItem::destroyView() removes entry from mItems
     }
 
 	while (!mFolders.empty())
 	{
 		LLFolderViewFolder *folderp = mFolders.back();
+        mFolders.pop_back();
 		folderp->destroyView(); // LLFolderVievFolder::destroyView() removes entry from mFolders
 	}
 
diff --git a/indra/newview/llfloatermarketplacelistings.cpp b/indra/newview/llfloatermarketplacelistings.cpp
index b1b397c77c..277bd5aaed 100755
--- a/indra/newview/llfloatermarketplacelistings.cpp
+++ b/indra/newview/llfloatermarketplacelistings.cpp
@@ -242,25 +242,15 @@ void LLFloaterMarketplaceListings::onOpen(const LLSD& key)
 	{
 		initializeMarketPlace();
 	}
-	else
-	{
-		setup();
+    else
+    {
+        updateView();
 	}
-	
-	//
-	// Update the floater view
-	//
-	updateView();
-	
-	//
-	// Trigger fetch of the contents
-	//
-	fetchContents();
 }
 
 void LLFloaterMarketplaceListings::onFocusReceived()
 {
-	fetchContents();
+	updateView();
 }
 
 void LLFloaterMarketplaceListings::fetchContents()
@@ -484,7 +474,6 @@ void LLFloaterMarketplaceListings::onChanged()
     LLViewerInventoryCategory* category = gInventory.getCategory(mRootFolderId);
 	if (mRootFolderId.notNull() && category)
     {
-        fetchContents();
         updateView();
     }
     else
diff --git a/indra/newview/llinventorymodel.cpp b/indra/newview/llinventorymodel.cpp
index 0fbccb2f3f..c379fb5f3a 100755
--- a/indra/newview/llinventorymodel.cpp
+++ b/indra/newview/llinventorymodel.cpp
@@ -1217,6 +1217,11 @@ void LLInventoryModel::deleteObject(const LLUUID& id)
 		LLViewerInventoryCategory* cat = (LLViewerInventoryCategory*)((LLInventoryObject*)obj);
 		cat_list->removeObj(cat);
 	}
+    
+    // Note : We need to tell the inventory observers that those things are going to be deleted *before* the tree is cleared or they won't know what to delete (in views and view models)
+	addChangedMask(LLInventoryObserver::REMOVE, id);
+	gInventory.notifyObservers();
+    
 	item_list = getUnlockedItemArray(id);
 	if(item_list)
 	{
@@ -1229,10 +1234,8 @@ void LLInventoryModel::deleteObject(const LLUUID& id)
 		delete cat_list;
 		mParentChildCategoryTree.erase(id);
 	}
-	addChangedMask(LLInventoryObserver::REMOVE, id);
 	obj = NULL; // delete obj
 	updateLinkedObjectsFromPurge(id);
-	gInventory.notifyObservers();
 }
 
 // Delete a particular inventory item by ID, and remove it from the server.
-- 
cgit v1.2.3