From 3861249a749c99c2a7b05d15ef82f8ff21453d05 Mon Sep 17 00:00:00 2001
From: Richard Linden <none@none>
Date: Tue, 3 Jan 2012 09:41:16 -0800
Subject: [PATCH] use lazy deletion of views via die() method to avoid some
 potential crashes

---
 indra/llui/llmenugl.cpp                  |  7 ++++++-
 indra/llui/llview.cpp                    |  6 ++++++
 indra/newview/llfavoritesbar.cpp         |  4 ++--
 indra/newview/llfloatercolorpicker.cpp   |  2 +-
 indra/newview/llfloatersnapshot.cpp      |  2 +-
 indra/newview/llfolderview.cpp           |  4 ++--
 indra/newview/llgrouplist.cpp            |  2 +-
 indra/newview/llpanelpeople.cpp          | 10 +++++-----
 indra/newview/llpanelprofile.cpp         |  2 +-
 indra/newview/llpanelteleporthistory.cpp |  2 +-
 10 files changed, 26 insertions(+), 15 deletions(-)

diff --git a/indra/llui/llmenugl.cpp b/indra/llui/llmenugl.cpp
index cb237fca7c8..95ecbb1c947 100644
--- a/indra/llui/llmenugl.cpp
+++ b/indra/llui/llmenugl.cpp
@@ -947,9 +947,14 @@ LLMenuItemBranchGL::LLMenuItemBranchGL(const LLMenuItemBranchGL::Params& p)
 
 LLMenuItemBranchGL::~LLMenuItemBranchGL()
 {
-	delete mBranchHandle.get();
+	if (mBranchHandle.get())
+	{
+		mBranchHandle.get()->die();
+	}
 }
 
+
+
 // virtual
 LLView* LLMenuItemBranchGL::getChildView(const std::string& name, BOOL recurse) const
 {
diff --git a/indra/llui/llview.cpp b/indra/llui/llview.cpp
index 486babb0ab9..15293817736 100644
--- a/indra/llui/llview.cpp
+++ b/indra/llui/llview.cpp
@@ -121,6 +121,7 @@ LLView::Params::Params()
 
 LLView::LLView(const LLView::Params& p)
 :	mVisible(p.visible),
+	mInDraw(false),
 	mName(p.name),
 	mParentView(NULL),
 	mReshapeFlags(FOLLOWS_NONE),
@@ -281,6 +282,8 @@ void LLView::moveChildToBackOfTabGroup(LLUICtrl* child)
 // virtual
 bool LLView::addChild(LLView* child, S32 tab_group)
 {
+	llassert_always(mInDraw == false);
+
 	if (!child)
 	{
 		return false;
@@ -330,6 +333,7 @@ bool LLView::addChildInBack(LLView* child, S32 tab_group)
 // remove the specified child from the view, and set it's parent to NULL.
 void LLView::removeChild(LLView* child)
 {
+	llassert_always(mInDraw == false);
 	//llassert_always(sDepth == 0); // Avoid re-ordering while drawing; it can cause subtle iterator bugs
 	if (child->mParentView == this) 
 	{
@@ -1081,6 +1085,7 @@ void LLView::draw()
 
 void LLView::drawChildren()
 {
+	mInDraw = true;
 	if (!mChildList.empty())
 	{
 		LLView* rootp = LLUI::getRootView();		
@@ -1119,6 +1124,7 @@ void LLView::drawChildren()
 		}
 		--sDepth;
 	}
+	mInDraw = false;
 }
 
 void LLView::dirtyRect()
diff --git a/indra/newview/llfavoritesbar.cpp b/indra/newview/llfavoritesbar.cpp
index 4f2fd474880..f4b6dc2c816 100644
--- a/indra/newview/llfavoritesbar.cpp
+++ b/indra/newview/llfavoritesbar.cpp
@@ -405,8 +405,8 @@ LLFavoritesBarCtrl::~LLFavoritesBarCtrl()
 {
 	gInventory.removeObserver(this);
 
-	delete mOverflowMenuHandle.get();
-	delete mContextMenuHandle.get();
+	if (mOverflowMenuHandle.get()) mOverflowMenuHandle.get()->die();
+	if (mContextMenuHandle.get()) mContextMenuHandle.get()->die();
 }
 
 BOOL LLFavoritesBarCtrl::handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop,
diff --git a/indra/newview/llfloatercolorpicker.cpp b/indra/newview/llfloatercolorpicker.cpp
index 659e52271af..05d73c24167 100644
--- a/indra/newview/llfloatercolorpicker.cpp
+++ b/indra/newview/llfloatercolorpicker.cpp
@@ -271,7 +271,7 @@ void LLFloaterColorPicker::destroyUI ()
 	if ( mSwatchView )
 	{
 		this->removeChild ( mSwatchView );
-		delete mSwatchView;
+		mSwatchView->die();;
 		mSwatchView = NULL;
 	}
 }
diff --git a/indra/newview/llfloatersnapshot.cpp b/indra/newview/llfloatersnapshot.cpp
index 1b3290d5a8f..2dd031b5d34 100644
--- a/indra/newview/llfloatersnapshot.cpp
+++ b/indra/newview/llfloatersnapshot.cpp
@@ -1977,7 +1977,7 @@ LLFloaterSnapshot::LLFloaterSnapshot(const LLSD& key)
 // Destroys the object
 LLFloaterSnapshot::~LLFloaterSnapshot()
 {
-	delete impl.mPreviewHandle.get();
+	if (impl.mPreviewHandle.get()) impl.mPreviewHandle.get()->die();
 
 	//unfreeze everything else
 	gSavedSettings.setBOOL("FreezeTime", FALSE);
diff --git a/indra/newview/llfolderview.cpp b/indra/newview/llfolderview.cpp
index 6ec2598e447..20fe85472fe 100644
--- a/indra/newview/llfolderview.cpp
+++ b/indra/newview/llfolderview.cpp
@@ -299,7 +299,7 @@ LLFolderView::~LLFolderView( void )
 	mAutoOpenItems.removeAllNodes();
 	gIdleCallbacks.deleteFunction(idle, this);
 
-	delete mPopupMenuHandle.get();
+	if (mPopupMenuHandle.get()) mPopupMenuHandle.get()->die();
 
 	mAutoOpenItems.removeAllNodes();
 	clearSelection();
@@ -1969,7 +1969,7 @@ BOOL LLFolderView::handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop,
 void LLFolderView::deleteAllChildren()
 {
 	closeRenamer();
-	delete mPopupMenuHandle.get();
+	if (mPopupMenuHandle.get()) mPopupMenuHandle.get()->die();
 	mPopupMenuHandle = LLHandle<LLView>();
 	mScrollContainer = NULL;
 	mRenameItem = NULL;
diff --git a/indra/newview/llgrouplist.cpp b/indra/newview/llgrouplist.cpp
index f7ed1116cbd..bbf66ca7503 100644
--- a/indra/newview/llgrouplist.cpp
+++ b/indra/newview/llgrouplist.cpp
@@ -95,7 +95,7 @@ LLGroupList::LLGroupList(const Params& p)
 LLGroupList::~LLGroupList()
 {
 	gAgent.removeListener(this);
-	delete mContextMenuHandle.get();
+	if (mContextMenuHandle.get()) mContextMenuHandle.get()->die();
 }
 
 // virtual
diff --git a/indra/newview/llpanelpeople.cpp b/indra/newview/llpanelpeople.cpp
index d5e289e6e6a..9c46f04abfd 100644
--- a/indra/newview/llpanelpeople.cpp
+++ b/indra/newview/llpanelpeople.cpp
@@ -526,11 +526,11 @@ LLPanelPeople::~LLPanelPeople()
 		LLVoiceClient::getInstance()->removeObserver(this);
 	}
 
-	delete mGroupPlusMenuHandle.get();
-	delete mNearbyViewSortMenuHandle.get();
-	delete mFriendsViewSortMenuHandle.get();
-	delete mGroupsViewSortMenuHandle.get();
-	delete mRecentViewSortMenuHandle.get();
+	if (mGroupPlusMenuHandle.get()) mGroupPlusMenuHandle.get()->die();
+	if (mNearbyViewSortMenuHandle.get()) mNearbyViewSortMenuHandle.get()->die();
+	if (mNearbyViewSortMenuHandle.get()) mNearbyViewSortMenuHandle.get()->die();
+	if (mGroupsViewSortMenuHandle.get()) mGroupsViewSortMenuHandle.get()->die();
+	if (mRecentViewSortMenuHandle.get()) mRecentViewSortMenuHandle.get()->die();
 
 }
 
diff --git a/indra/newview/llpanelprofile.cpp b/indra/newview/llpanelprofile.cpp
index b1eeabb0282..e2e70067737 100755
--- a/indra/newview/llpanelprofile.cpp
+++ b/indra/newview/llpanelprofile.cpp
@@ -177,7 +177,7 @@ LLPanelProfile::ChildStack::~ChildStack()
 			LLView* viewp = *it;
 			if (viewp)
 			{
-				delete viewp;
+				viewp->die();
 			}
 		}
 		mStack.pop_back();
diff --git a/indra/newview/llpanelteleporthistory.cpp b/indra/newview/llpanelteleporthistory.cpp
index d3543daff08..1f1cccad856 100644
--- a/indra/newview/llpanelteleporthistory.cpp
+++ b/indra/newview/llpanelteleporthistory.cpp
@@ -388,7 +388,7 @@ LLTeleportHistoryPanel::LLTeleportHistoryPanel()
 LLTeleportHistoryPanel::~LLTeleportHistoryPanel()
 {
 	LLTeleportHistoryFlatItemStorage::instance().purge();
-	delete mGearMenuHandle.get();
+	if (mGearMenuHandle.get()) mGearMenuHandle.get()->die();
 	mTeleportHistoryChangedConnection.disconnect();
 }
 
-- 
GitLab