From 8cef480b96dc779c5879f74224fb0a185ee550f2 Mon Sep 17 00:00:00 2001
From: Xiaohong Bao <bao@lindenlab.com>
Date: Mon, 29 Aug 2011 18:15:38 -0600
Subject: [PATCH] fix for SH-2311: crash at LLVOVolume::lineSegmentIntersect
 line 3435 and SH-2358: Crash in LLError::crashAndLoop: Invalid face index

---
 indra/llmath/llvolume.cpp    | 2 +-
 indra/newview/llvovolume.cpp | 7 ++++++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/indra/llmath/llvolume.cpp b/indra/llmath/llvolume.cpp
index b2fe9ba6c24..1a95f9cd463 100755
--- a/indra/llmath/llvolume.cpp
+++ b/indra/llmath/llvolume.cpp
@@ -2734,7 +2734,7 @@ void LLVolume::cacheOptimize()
 
 S32	LLVolume::getNumFaces() const
 {
-	return (S32)mProfilep->mFaces.size();
+	return mIsMeshAssetLoaded ? getNumVolumeFaces() : (S32)mProfilep->mFaces.size();
 }
 
 
diff --git a/indra/newview/llvovolume.cpp b/indra/newview/llvovolume.cpp
index d3ef1771c32..6b0a5d8642f 100755
--- a/indra/newview/llvovolume.cpp
+++ b/indra/newview/llvovolume.cpp
@@ -1660,11 +1660,16 @@ BOOL LLVOVolume::updateGeometry(LLDrawable *drawable)
 			compiled = TRUE;
 			sNumLODChanges += new_num_faces ;
 	
+			if((S32)getNumTEs() != getVolume()->getNumFaces())
+			{
+				setNumTEs(getVolume()->getNumFaces()); //mesh loading may change number of faces.
+			}
+
 			drawable->setState(LLDrawable::REBUILD_VOLUME); // for face->genVolumeTriangles()
 
 			{
 				LLFastTimer t(FTM_GEN_TRIANGLES);
-				if (new_num_faces != old_num_faces)
+				if (new_num_faces != old_num_faces || mNumFaces != (S32)getNumTEs())
 				{
 					regenFaces();
 				}
-- 
GitLab