From b38170e6817b3f69274d9b5953584a1278a17ca2 Mon Sep 17 00:00:00 2001
From: Xiaohong Bao <bao@lindenlab.com>
Date: Wed, 19 Jun 2013 11:45:44 -0600
Subject: [PATCH] fix for SH-4245: Interesting: crash in
 LLSpatialGroup::handleDestruction

---
 indra/newview/llspatialpartition.cpp | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/indra/newview/llspatialpartition.cpp b/indra/newview/llspatialpartition.cpp
index 45130efeb9f..b9d4c016c27 100755
--- a/indra/newview/llspatialpartition.cpp
+++ b/indra/newview/llspatialpartition.cpp
@@ -841,11 +841,16 @@ void LLSpatialGroup::handleRemoval(const TreeNode* node, LLViewerOctreeEntry* en
 
 void LLSpatialGroup::handleDestruction(const TreeNode* node)
 {
+	if(isDead())
+	{
+		return;
+	}
 	setState(DEAD);
 	
-	for (element_iter i = getDataBegin(); i != getDataEnd(); ++i)
+	for (element_iter i = getDataBegin(); getElementCount() > 0 && i != getDataEnd();)
 	{
 		LLViewerOctreeEntry* entry = *i;
+
 		if (entry->getGroup() == this)
 		{
 			if(entry->hasDrawable())
@@ -853,10 +858,14 @@ void LLSpatialGroup::handleDestruction(const TreeNode* node)
 				((LLDrawable*)entry->getDrawable())->setGroup(NULL);
 			}
 			else
-		{
+			{
 				llerrs << "No Drawable found in the entry." << llendl;
 			}
 		}
+		else
+		{
+			++i;
+		}
 	}
 	
 	//clean up avatar attachment stats
-- 
GitLab