From 0ffc73855b02bf4679c42cdb20e00544922f8407 Mon Sep 17 00:00:00 2001
From: Loren Shih <seraph@lindenlab.com>
Date: Mon, 29 Mar 2010 13:50:37 -0400
Subject: [PATCH] EXT-6536 : Make LLVOAvatarSelf a singleton

Fix for cleaning up gAgentAvatar on app shutdown.
---
 indra/newview/llappviewer.cpp        |  1 +
 indra/newview/llviewerobjectlist.cpp |  3 ++-
 indra/newview/llvoavatarself.cpp     | 11 +++++++++--
 indra/newview/llvoavatarself.h       |  1 +
 4 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp
index a8d69a38cd9..8eab4bf508f 100644
--- a/indra/newview/llappviewer.cpp
+++ b/indra/newview/llappviewer.cpp
@@ -4085,6 +4085,7 @@ void LLAppViewer::disconnectViewer()
 	gAgentCamera.cleanup();
 	// Also writes cached agent settings to gSavedSettings
 	gAgent.cleanup();
+	delete gAgentAvatarp;
 
 	// This is where we used to call gObjectList.destroy() and then delete gWorldp.
 	// Now we just ask the LLWorld singleton to cleanly shut down.
diff --git a/indra/newview/llviewerobjectlist.cpp b/indra/newview/llviewerobjectlist.cpp
index 5e0bd5b811b..752aeaaab01 100644
--- a/indra/newview/llviewerobjectlist.cpp
+++ b/indra/newview/llviewerobjectlist.cpp
@@ -949,7 +949,8 @@ void LLViewerObjectList::killAllObjects()
 	{
 		objectp = *iter;
 		killObject(objectp);
-		llassert(objectp->isDead());
+		// Object must be dead, or it's the LLVOAvatarSelf which never dies.
+		llassert((objectp == gAgentAvatarp) || objectp->isDead());
 	}
 
 	cleanDeadObjects(FALSE);
diff --git a/indra/newview/llvoavatarself.cpp b/indra/newview/llvoavatarself.cpp
index d58be219107..06c9af6c2ff 100644
--- a/indra/newview/llvoavatarself.cpp
+++ b/indra/newview/llvoavatarself.cpp
@@ -518,10 +518,17 @@ BOOL LLVOAvatarSelf::buildMenus()
 	return TRUE;
 }
 
+LLVOAvatarSelf::cleanup()
+{
+	markDead();
+ 	delete mScreenp;
+ 	mScreenp = NULL;
+	mRegionp = NULL;
+}
+
 LLVOAvatarSelf::~LLVOAvatarSelf()
 {
-	delete mScreenp;
-	mScreenp = NULL;
+	cleanup();
 }
 
 /**
diff --git a/indra/newview/llvoavatarself.h b/indra/newview/llvoavatarself.h
index 3c7ec04fabb..4960d4d1034 100644
--- a/indra/newview/llvoavatarself.h
+++ b/indra/newview/llvoavatarself.h
@@ -56,6 +56,7 @@ class LLVOAvatarSelf :
 	virtual 				~LLVOAvatarSelf();
 	virtual void			markDead();
 	virtual void 			initInstance(); // Called after construction to initialize the class.
+	void					cleanup();
 protected:
 	/*virtual*/ BOOL		loadAvatar();
 	BOOL					loadAvatarSelf();
-- 
GitLab