From 712a4e70c81c1908e4e7668ff1695a9415ec4b71 Mon Sep 17 00:00:00 2001
From: Oz Linden <oz@lindenlab.com>
Date: Wed, 26 Aug 2015 12:07:16 -0400
Subject: [PATCH] refine fix for MAINT-5560 based on review feedback and to fix
 VS objection

---
 indra/newview/llavatarrenderinfoaccountant.cpp |  4 +++-
 indra/newview/llspatialpartition.cpp           |  3 +--
 indra/newview/llvoavatar.cpp                   | 11 ++++++-----
 indra/newview/llvoavatar.h                     |  4 ++--
 indra/newview/llvovolume.cpp                   |  6 ++----
 5 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/indra/newview/llavatarrenderinfoaccountant.cpp b/indra/newview/llavatarrenderinfoaccountant.cpp
index 03204ea48fc..d351b38653d 100644
--- a/indra/newview/llavatarrenderinfoaccountant.cpp
+++ b/indra/newview/llavatarrenderinfoaccountant.cpp
@@ -268,8 +268,10 @@ void LLAvatarRenderInfoAccountant::sendRenderInfoToRegion(LLViewerRegion * regio
 
 					LLSD info = LLSD::emptyMap();
                     U32 avatar_complexity = avatar->getVisualComplexity();
-					if (avatar_complexity > 0)
+                    if (avatar_complexity > 0)
 					{
+                        // the weight/complexity is unsigned, but LLSD only stores signed integers,
+                        // so if it's over that (which would be ridiculously high), just store the maximum signed int value
 						info[KEY_WEIGHT] = (S32)(avatar_complexity < S32_MAX ? avatar_complexity : S32_MAX);
 						info[KEY_TOO_COMPLEX]  = LLSD::Boolean(avatar->isTooComplex());
 						agents[avatar->getID().asString()] = info;
diff --git a/indra/newview/llspatialpartition.cpp b/indra/newview/llspatialpartition.cpp
index 11b619ba006..da3f344e007 100755
--- a/indra/newview/llspatialpartition.cpp
+++ b/indra/newview/llspatialpartition.cpp
@@ -862,8 +862,7 @@ void LLSpatialGroup::handleDestruction(const TreeNode* node)
 	{
 		if (bridge->mAvatar.notNull())
 		{
-			bridge->mAvatar->modifyAttachmentGeometryBytes( -mGeometryBytes );
-			bridge->mAvatar->modifyAttachmentSurfaceArea( -mSurfaceArea );
+			bridge->mAvatar->subtractAttachmentSizes( mGeometryBytes, mSurfaceArea );
 		}
 	}
 
diff --git a/indra/newview/llvoavatar.cpp b/indra/newview/llvoavatar.cpp
index 303b677dcf5..5d83a20f509 100755
--- a/indra/newview/llvoavatar.cpp
+++ b/indra/newview/llvoavatar.cpp
@@ -8283,15 +8283,16 @@ void LLVOAvatar::idleUpdateRenderComplexity()
 	}
 }
 
-void LLVOAvatar::modifyAttachmentGeometryBytes(S32 delta)
+void LLVOAvatar::addAttachmentSizes(U32 delta_bytes, F32 delta_area)
 {
-    mAttachmentGeometryBytes = llmax(mAttachmentGeometryBytes + delta, 0);
+    mAttachmentGeometryBytes += delta_bytes;
+    mAttachmentSurfaceArea   += delta_area;
 }
 
-void LLVOAvatar::modifyAttachmentSurfaceArea(F32 delta)
+void LLVOAvatar::subtractAttachmentSizes(U32 delta_bytes, F32 delta_area)
 {
-    F32 newval = mAttachmentSurfaceArea + delta;
-    mAttachmentSurfaceArea = ( newval > 0.0 ? newval : 0.0 );
+    mAttachmentGeometryBytes = delta_bytes > mAttachmentGeometryBytes ? 0 : mAttachmentGeometryBytes - delta_bytes;
+    mAttachmentSurfaceArea   = delta_area > mAttachmentSurfaceArea ? 0.0 : mAttachmentSurfaceArea - delta_area;
 }
 
 void LLVOAvatar::updateVisualComplexity()
diff --git a/indra/newview/llvoavatar.h b/indra/newview/llvoavatar.h
index 5f690be4c56..fb19f4eb2ec 100755
--- a/indra/newview/llvoavatar.h
+++ b/indra/newview/llvoavatar.h
@@ -258,9 +258,9 @@ class LLVOAvatar :
 	
 	U32				getVisualComplexity()			{ return mVisualComplexity;				};		// Numbers calculated here by rendering AV
 	S32				getAttachmentGeometryBytes()	{ return mAttachmentGeometryBytes;		};		// number of bytes in attached geometry
-    void            modifyAttachmentGeometryBytes(S32 delta);
 	F32				getAttachmentSurfaceArea()		{ return mAttachmentSurfaceArea;		};		// estimated surface area of attachments
-    void            modifyAttachmentSurfaceArea(F32 delta);
+    void            addAttachmentSizes(U32 delta_bytes, F32 delta_area);
+    void            subtractAttachmentSizes(U32 delta_bytes, F32 delta_area);
 
 	U32				getReportedVisualComplexity()					{ return mReportedVisualComplexity;				};	// Numbers as reported by the SL server
 	void			setReportedVisualComplexity(U32 value)			{ mReportedVisualComplexity = value;			};
diff --git a/indra/newview/llvovolume.cpp b/indra/newview/llvovolume.cpp
index 160e2fbdb35..44ba09c1711 100755
--- a/indra/newview/llvovolume.cpp
+++ b/indra/newview/llvovolume.cpp
@@ -4703,8 +4703,7 @@ void LLVolumeGeometryManager::rebuildGeom(LLSpatialGroup* group)
 
 	if (pAvatarVO)
 	{
-		pAvatarVO->modifyAttachmentGeometryBytes( -group->mGeometryBytes );
-		pAvatarVO->modifyAttachmentSurfaceArea( -group->mSurfaceArea );
+		pAvatarVO->subtractAttachmentSizes( group->mGeometryBytes, group->mSurfaceArea );
 	}
 
 	group->mGeometryBytes = 0;
@@ -5258,8 +5257,7 @@ void LLVolumeGeometryManager::rebuildGeom(LLSpatialGroup* group)
 
 	if (pAvatarVO)
 	{
-        pAvatarVO->modifyAttachmentGeometryBytes( group->mGeometryBytes );
-		pAvatarVO->modifyAttachmentSurfaceArea( group->mSurfaceArea );
+        pAvatarVO->addAttachmentSizes( group->mGeometryBytes, group->mSurfaceArea );
 	}
 }
 
-- 
GitLab