From 10069e0e13e3214ba9320fdce915440b2e12f938 Mon Sep 17 00:00:00 2001
From: Dave Parks <davep@lindenlab.com>
Date: Thu, 5 Nov 2009 19:58:10 -0600
Subject: [PATCH] Fix for prims all being 0 lod. Fix for dangling prim
 references.

---
 indra/llmath/llvolume.cpp         | 3 ++-
 indra/llprimitive/llprimitive.cpp | 8 +++++++-
 indra/newview/llvovolume.cpp      | 2 +-
 indra/newview/pipeline.cpp        | 2 ++
 4 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/indra/llmath/llvolume.cpp b/indra/llmath/llvolume.cpp
index ddd1b4b3db..33a8d33ce1 100644
--- a/indra/llmath/llvolume.cpp
+++ b/indra/llmath/llvolume.cpp
@@ -1692,9 +1692,10 @@ LLVolume::LLVolume(const LLVolumeParams &params, const F32 detail, const BOOL ge
 
 	mLODScaleBias.setVec(1,1,1);
 
+	generate();
+
 	if (mParams.getSculptID().isNull() && params.getSculptType() == LL_SCULPT_TYPE_NONE)
 	{
-		generate();
 		createVolumeFaces();
 	}
 }
diff --git a/indra/llprimitive/llprimitive.cpp b/indra/llprimitive/llprimitive.cpp
index 52265e7ad5..340f60ed1a 100644
--- a/indra/llprimitive/llprimitive.cpp
+++ b/indra/llprimitive/llprimitive.cpp
@@ -744,7 +744,10 @@ BOOL LLPrimitive::setVolume(const LLVolumeParams &volume_params, const S32 detai
 		return TRUE;
 	}
 	
-#if 0
+#if 0 
+	// #if 0'd out by davep
+	// this is a lot of cruft to set texture entry values that just stay the same for LOD switch 
+	// or immediately get overridden by an object update message, also crashes occasionally
 	U32 old_face_mask = mVolumep->mFaceMask;
 
 	S32 face_bit = 0;
@@ -943,6 +946,9 @@ BOOL LLPrimitive::setVolume(const LLVolumeParams &volume_params, const S32 detai
 		}
 	}
 #else
+	// build the new object
+	sVolumeManager->unrefVolume(mVolumep);
+	mVolumep = volumep;
 	setNumTEs(mVolumep->getNumFaces());
 #endif
 	return TRUE;
diff --git a/indra/newview/llvovolume.cpp b/indra/newview/llvovolume.cpp
index 78fd371087..7666009a62 100644
--- a/indra/newview/llvovolume.cpp
+++ b/indra/newview/llvovolume.cpp
@@ -919,7 +919,7 @@ BOOL LLVOVolume::setVolume(const LLVolumeParams &params, const S32 detail, bool
 				{
 					//mesh is not loaded, request pipeline load this mesh
 					LLUUID asset_id = volume_params.getSculptID();
-					gPipeline.loadMesh(this, asset_id);
+					gPipeline.loadMesh(this, asset_id, detail);
 				}
 				else
 				{
diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp
index 4ac95fa939..3554ceb7f0 100644
--- a/indra/newview/pipeline.cpp
+++ b/indra/newview/pipeline.cpp
@@ -8949,6 +8949,7 @@ void LLPipeline::loadMesh(LLVOVolume* vobj, LLUUID mesh_id, S32 detail)
 					group->derefLOD(lod);
 					return;
 				}
+				group->derefLOD(lod);
 			}
 
 			//no lower LOD is a available, is a higher lod available?
@@ -8961,6 +8962,7 @@ void LLPipeline::loadMesh(LLVOVolume* vobj, LLUUID mesh_id, S32 detail)
 					group->derefLOD(lod);
 					return;
 				}
+				group->derefLOD(lod);
 			}
 		}
 	}
-- 
GitLab