From 791da71c3ea45130cd3817a059a18418e43269b0 Mon Sep 17 00:00:00 2001
From: Leslie Linden <leslie@lindenlab.com>
Date: Thu, 7 Jul 2011 10:37:50 -0700
Subject: EXP-983 FIX -- Viewer crashes around Place Profile and Landmarks
 listing in Viewer Experience

* Fixed up some funny use of objects that had already been deleted.

Reviewed by Richard.
---
 indra/newview/llinventorypanel.cpp | 21 ++++++++++++---------
 indra/newview/llinventorypanel.h   |  4 ++--
 2 files changed, 14 insertions(+), 11 deletions(-)

(limited to 'indra/newview')

diff --git a/indra/newview/llinventorypanel.cpp b/indra/newview/llinventorypanel.cpp
index 8f947b15b9..84199a895a 100644
--- a/indra/newview/llinventorypanel.cpp
+++ b/indra/newview/llinventorypanel.cpp
@@ -471,7 +471,8 @@ void LLInventoryPanel::modelChanged(U32 mask)
 			{
 				view_item->destroyView();
 			}
-			buildNewViews(item_id);
+			view_item = buildNewViews(item_id);
+			view_folder = dynamic_cast<LLFolderViewFolder *>(view_item);
 		}
 
 		//////////////////////////////
@@ -524,7 +525,7 @@ void LLInventoryPanel::modelChanged(U32 mask)
 			//////////////////////////////
 			// STRUCTURE Operation
 			// This item already exists in both memory and UI.  It was probably reparented.
-			if (model_item && view_item)
+			else if (model_item && view_item)
 			{
 				// Don't process the item if it is the root
 				if (view_item->getRoot() != view_item)
@@ -552,7 +553,7 @@ void LLInventoryPanel::modelChanged(U32 mask)
 			//////////////////////////////
 			// REMOVE Operation
 			// This item has been removed from memory, but its associated UI element still exists.
-			if (!model_item && view_item)
+			else if (!model_item && view_item)
 			{
 				// Remove the item's UI.
 				view_item->destroyView();
@@ -619,7 +620,7 @@ void LLInventoryPanel::initializeViews()
 	}
 }
 
-void LLInventoryPanel::rebuildViewsFor(const LLUUID& id)
+LLFolderViewItem* LLInventoryPanel::rebuildViewsFor(const LLUUID& id)
 {
 	// Destroy the old view for this ID so we can rebuild it.
 	LLFolderViewItem* old_view = mFolderRoot->getItemByID(id);
@@ -628,7 +629,7 @@ void LLInventoryPanel::rebuildViewsFor(const LLUUID& id)
 		old_view->destroyView();
 	}
 
-	buildNewViews(id);
+	return buildNewViews(id);
 }
 
 LLFolderView * LLInventoryPanel::createFolderView(LLInvFVBridge * bridge, bool useLabelSuffix)
@@ -695,19 +696,19 @@ LLFolderViewItem * LLInventoryPanel::createFolderViewItem(LLInvFVBridge * bridge
 	return LLUICtrlFactory::create<LLFolderViewItem>(params);
 }
 
-void LLInventoryPanel::buildNewViews(const LLUUID& id)
+LLFolderViewItem* LLInventoryPanel::buildNewViews(const LLUUID& id)
 {
  	LLInventoryObject const* objectp = gInventory.getObject(id);
  	LLUUID root_id = mFolderRoot->getListener()->getUUID();
  	LLFolderViewFolder* parent_folder = NULL;
- 
+	LLFolderViewItem* itemp = NULL;
+	
  	if (id == root_id)
  	{
  		parent_folder = mFolderRoot;
  	}
  	else if (objectp)
  	{
- 		LLFolderViewItem* itemp = NULL;
  		const LLUUID &parent_id = objectp->getParentUUID();
  		parent_folder = (LLFolderViewFolder*)mFolderRoot->getItemByID(parent_id);
   		
@@ -719,7 +720,7 @@ void LLInventoryPanel::buildNewViews(const LLUUID& id)
   				llwarns << "LLInventoryPanel::buildNewViews called with invalid objectp->mType : "
   						<< ((S32) objectp->getType()) << " name " << objectp->getName() << " UUID " << objectp->getUUID()
   						<< llendl;
-  				return;
+  				return NULL;
   			}
   		
   			if ((objectp->getType() == LLAssetType::AT_CATEGORY) &&
@@ -796,6 +797,8 @@ void LLInventoryPanel::buildNewViews(const LLUUID& id)
 		}
 		mInventory->unlockDirectDescendentArrays(id);
 	}
+	
+	return itemp;
 }
 
 // bit of a hack to make sure the inventory is open.
diff --git a/indra/newview/llinventorypanel.h b/indra/newview/llinventorypanel.h
index 4894b43a56..a4287a438e 100644
--- a/indra/newview/llinventorypanel.h
+++ b/indra/newview/llinventorypanel.h
@@ -220,10 +220,10 @@ public:
 protected:
 	// Builds the UI.  Call this once the inventory is usable.
 	void 				initializeViews();
-	void				rebuildViewsFor(const LLUUID& id); // Given the id and the parent, build all of the folder views.
+	LLFolderViewItem*	rebuildViewsFor(const LLUUID& id); // Given the id and the parent, build all of the folder views.
 
 	virtual void		buildFolderView(const LLInventoryPanel::Params& params);
-	virtual void		buildNewViews(const LLUUID& id);
+	LLFolderViewItem*	buildNewViews(const LLUUID& id);
 	BOOL				getIsHiddenFolderType(LLFolderType::EType folder_type) const;
 	
 	virtual LLFolderView*		createFolderView(LLInvFVBridge * bridge, bool useLabelSuffix);
-- 
cgit v1.2.3