From 3bab3fc66183f124d173b4ec192c03a9205788d9 Mon Sep 17 00:00:00 2001
From: Richard Linden <none@none>
Date: Wed, 29 Sep 2010 15:02:32 -0700
Subject: [PATCH] fix for crash on exit also made handle subtyping work

---
 indra/llui/llhandle.h     |  2 +-
 indra/llui/lllineeditor.h |  2 +-
 indra/llui/llmenugl.cpp   | 24 +++++++++++-------------
 indra/llui/llmenugl.h     |  7 +++++--
 4 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/indra/llui/llhandle.h b/indra/llui/llhandle.h
index a43f095d675..a198a26c227 100644
--- a/indra/llui/llhandle.h
+++ b/indra/llui/llhandle.h
@@ -99,9 +99,9 @@ class LLHandle
 	{
 		return lhs.mTombStone > rhs.mTombStone;
 	}
-protected:
 
 protected:
+	template<typename T> friend class LLHandle;
 	LLPointer<LLTombStone<T> > mTombStone;
 
 private:
diff --git a/indra/llui/lllineeditor.h b/indra/llui/lllineeditor.h
index 76d01877128..66fe8304e29 100644
--- a/indra/llui/lllineeditor.h
+++ b/indra/llui/lllineeditor.h
@@ -326,7 +326,7 @@ class LLLineEditor
 	std::vector<S32> mPreeditPositions;
 	LLPreeditor::standouts_t mPreeditStandouts;
 
-	LLHandle<LLView> mContextMenuHandle;
+	LLHandle<LLContextMenu> mContextMenuHandle;
 
 private:
 	// Instances that by default point to the statics but can be overidden in XML.
diff --git a/indra/llui/llmenugl.cpp b/indra/llui/llmenugl.cpp
index 67993988fe3..64f84bae7c4 100644
--- a/indra/llui/llmenugl.cpp
+++ b/indra/llui/llmenugl.cpp
@@ -3694,9 +3694,7 @@ class LLContextMenuBranch : public LLMenuItemGL
 	LLContextMenuBranch(const Params&);
 
 	virtual ~LLContextMenuBranch()
-	{
-		delete mBranch;
-	}
+	{}
 
 	// called to rebuild the draw label
 	virtual void	buildDrawLabel( void );
@@ -3704,21 +3702,21 @@ class LLContextMenuBranch : public LLMenuItemGL
 	// onCommit() - do the primary funcationality of the menu item.
 	virtual void	onCommit( void );
 
-	LLContextMenu*	getBranch() { return mBranch; }
+	LLContextMenu*	getBranch() { return mBranch.get(); }
 	void			setHighlight( BOOL highlight );
 
 protected:
 	void	showSubMenu();
 
-	LLContextMenu* mBranch;
+	LLHandle<LLContextMenu> mBranch;
 };
 
 LLContextMenuBranch::LLContextMenuBranch(const LLContextMenuBranch::Params& p) 
 :	LLMenuItemGL(p),
-	mBranch( p.branch )
+	mBranch( p.branch()->getHandle() )
 {
-	mBranch->hide();
-	mBranch->setParentMenuItem(this);
+	mBranch.get()->hide();
+	mBranch.get()->setParentMenuItem(this);
 }
 
 // called to rebuild the draw label
@@ -3727,12 +3725,12 @@ void LLContextMenuBranch::buildDrawLabel( void )
 	{
 		// default enablement is this -- if any of the subitems are
 		// enabled, this item is enabled. JC
-		U32 sub_count = mBranch->getItemCount();
+		U32 sub_count = mBranch.get()->getItemCount();
 		U32 i;
 		BOOL any_enabled = FALSE;
 		for (i = 0; i < sub_count; i++)
 		{
-			LLMenuItemGL* item = mBranch->getItem(i);
+			LLMenuItemGL* item = mBranch.get()->getItem(i);
 			item->buildDrawLabel();
 			if (item->getEnabled() && !item->getDrawTextDisabled() )
 			{
@@ -3754,13 +3752,13 @@ void LLContextMenuBranch::buildDrawLabel( void )
 
 void	LLContextMenuBranch::showSubMenu()
 {
-	LLMenuItemGL* menu_item = mBranch->getParentMenuItem();
+	LLMenuItemGL* menu_item = mBranch.get()->getParentMenuItem();
 	if (menu_item != NULL && menu_item->getVisible())
 	{
 		S32 center_x;
 		S32 center_y;
 		localPointToScreen(getRect().getWidth(), getRect().getHeight() , &center_x, &center_y);
-		mBranch->show(center_x, center_y);
+		mBranch.get()->show(center_x, center_y);
 	}
 }
 
@@ -3780,7 +3778,7 @@ void LLContextMenuBranch::setHighlight( BOOL highlight )
 	}
 	else
 	{
-		mBranch->hide();
+		mBranch.get()->hide();
 	}
 }
 
diff --git a/indra/llui/llmenugl.h b/indra/llui/llmenugl.h
index 19b738312e8..bb17bf4102e 100644
--- a/indra/llui/llmenugl.h
+++ b/indra/llui/llmenugl.h
@@ -670,9 +670,12 @@ class LLContextMenu
 
 			BOOL	appendContextSubMenu(LLContextMenu *menu);
 
+			LLHandle<LLContextMenu> getHandle() { mHandle.bind(this); return mHandle; }
+
 protected:
-	BOOL			mHoveredAnyItem;
-	LLMenuItemGL*	mHoverItem;
+	BOOL						mHoveredAnyItem;
+	LLMenuItemGL*				mHoverItem;
+	LLRootHandle<LLContextMenu>	mHandle;
 };
 
 
-- 
GitLab