From 6d66910c6e2fbb25bf8b5c7b90e795f350342104 Mon Sep 17 00:00:00 2001
From: Dave Parks <davep@lindenlab.com>
Date: Wed, 25 Nov 2009 11:35:41 -0600
Subject: Fix for spam on invalid mesh asset. Fix for index buffer overflow
 spam and crash in llvertexbuffer.

---
 indra/llmath/llvolume.cpp    |  5 -----
 indra/newview/llvovolume.cpp |  5 +++--
 indra/newview/pipeline.cpp   | 18 ++++++------------
 3 files changed, 9 insertions(+), 19 deletions(-)

diff --git a/indra/llmath/llvolume.cpp b/indra/llmath/llvolume.cpp
index 515b1061f9..3e547aec6f 100644
--- a/indra/llmath/llvolume.cpp
+++ b/indra/llmath/llvolume.cpp
@@ -2245,11 +2245,6 @@ void LLVolume::makeTetrahedron()
 
 void LLVolume::copyVolumeFaces(LLVolume* volume)
 {
-	if (volume->isTetrahedron())
-	{
-		llerrs << "WTF?" << llendl;
-	}
-
 	mVolumeFaces = volume->mVolumeFaces;
 	mSculptLevel = 0;
 	mIsTetrahedron = FALSE;
diff --git a/indra/newview/llvovolume.cpp b/indra/newview/llvovolume.cpp
index 64c2e9e8ec..3e9db86cfa 100644
--- a/indra/newview/llvovolume.cpp
+++ b/indra/newview/llvovolume.cpp
@@ -882,7 +882,7 @@ BOOL LLVOVolume::setVolume(const LLVolumeParams &params, const S32 detail, bool
 			// if it's a mesh
 			if ((volume_params.getSculptType() & LL_SCULPT_TYPE_MASK) == LL_SCULPT_TYPE_MESH)
 			{
-				if (getVolume()->getNumVolumeFaces() == 0)
+				if (getVolume()->getNumVolumeFaces() == 0 || getVolume()->isTetrahedron())
 				{ 
 					//load request not yet issued, request pipeline load this mesh
 					LLUUID asset_id = volume_params.getSculptID();
@@ -924,7 +924,8 @@ BOOL LLVOVolume::setVolume(const LLVolumeParams &params, const S32 detail, bool
 void LLVOVolume::notifyMeshLoaded()
 { 
 	mSculptChanged = TRUE;
-	gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_GEOMETRY);
+	gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_GEOMETRY, TRUE);
+	dirtySpatialGroup(TRUE);
 }
 
 // sculpt replaces generate() for sculpted surfaces
diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp
index 0ee619244b..af3a35615c 100644
--- a/indra/newview/pipeline.cpp
+++ b/indra/newview/pipeline.cpp
@@ -1807,8 +1807,6 @@ void LLPipeline::rebuildPriorityGroups()
 	
 	assertInitialized();
 
-	notifyLoadedMeshes();
-
 	// Iterate through all drawables on the priority build queue,
 	for (LLSpatialGroup::sg_list_t::iterator iter = mGroupQ1.begin();
 		 iter != mGroupQ1.end(); ++iter)
@@ -1888,6 +1886,8 @@ void LLPipeline::updateGeom(F32 max_dtime)
 	// for now, only LLVOVolume does this to throttle LOD changes
 	LLVOVolume::preUpdateGeom();
 
+	notifyLoadedMeshes();
+
 	// Iterate through all drawables on the priority build queue,
 	for (LLDrawable::drawable_list_t::iterator iter = mBuildQ1.begin();
 		 iter != mBuildQ1.end();)
@@ -8913,7 +8913,6 @@ LLCullResult::sg_list_t::iterator LLPipeline::endAlphaGroups()
 
 void LLPipeline::loadMesh(LLVOVolume* vobj, LLUUID mesh_id, S32 detail)
 {
-
 	if (detail < 0 || detail > 4)
 	{
 		return;
@@ -9093,10 +9092,6 @@ void LLPipeline::notifyLoadedMeshes()
 
 	for (std::list<LLMeshThread*>::iterator iter = mLoadedMeshes.begin(); iter != mLoadedMeshes.end(); ++iter)
 	{ //for each mesh done loading
-
-
-
-
 		LLMeshThread* mesh = *iter;
 		
 		if (!mesh->isStopped())
@@ -9131,14 +9126,13 @@ void LLPipeline::notifyLoadedMeshes()
 
 			if (valid)
 			{
-				if (mesh->mVolume->getNumVolumeFaces() > 0)
-				{
-					mesh->mTargetVolume->copyVolumeFaces(mesh->mVolume);
-				}
-				else
+				if (mesh->mVolume->getNumVolumeFaces() <= 0)
 				{
 					llwarns << "Mesh loading returned empty volume." << llendl;
+					mesh->mVolume->makeTetrahedron();
 				}
+				
+				mesh->mTargetVolume->copyVolumeFaces(mesh->mVolume);
 
 				for (std::set<LLUUID>::iterator vobj_iter = obj_iter->second.begin(); vobj_iter != obj_iter->second.end(); ++vobj_iter)
 				{
-- 
cgit v1.2.3