From c79e648aac9bb32cc1d49d39973b5e96f25828f0 Mon Sep 17 00:00:00 2001
From: "Brad Payne (Vir Linden)" <vir@lindenlab.com>
Date: Wed, 4 Nov 2020 16:07:10 +0000
Subject: [PATCH] SL-14015 - possible fix for phantom animesh attachments on
 mac

---
 indra/newview/llcontrolavatar.cpp  | 82 ++++++++++++++++--------------
 indra/newview/llcontrolavatar.h    |  4 ++
 indra/newview/lldrawpoolavatar.cpp |  7 +++
 indra/newview/llvoavatar.cpp       |  4 +-
 indra/newview/llvoavatar.h         |  6 +++
 5 files changed, 64 insertions(+), 39 deletions(-)

diff --git a/indra/newview/llcontrolavatar.cpp b/indra/newview/llcontrolavatar.cpp
index f732f369bdf..fab249f9880 100644
--- a/indra/newview/llcontrolavatar.cpp
+++ b/indra/newview/llcontrolavatar.cpp
@@ -78,6 +78,24 @@ void LLControlAvatar::initInstance()
     mInitFlags |= 1<<4;
 }
 
+const LLVOAvatar *LLControlAvatar::getAttachedAvatar() const
+{
+	if (mRootVolp && mRootVolp->isAttachment())
+	{
+		return mRootVolp->getAvatarAncestor();
+	}
+	return NULL;
+}
+
+LLVOAvatar *LLControlAvatar::getAttachedAvatar()
+{
+	if (mRootVolp && mRootVolp->isAttachment())
+	{
+		return mRootVolp->getAvatarAncestor();
+	}
+	return NULL;
+}
+
 void LLControlAvatar::getNewConstraintFixups(LLVector3& new_pos_fixup, F32& new_scale_fixup) const
 {
 
@@ -165,7 +183,7 @@ void LLControlAvatar::matchVolumeTransform()
 
         if (mRootVolp->isAttachment())
         {
-            LLVOAvatar *attached_av = mRootVolp->getAvatarAncestor();
+            LLVOAvatar *attached_av = getAttachedAvatar();
             if (attached_av)
             {
                 LLViewerJointAttachment *attach = attached_av->getTargetAttachmentPoint(mRootVolp);
@@ -365,28 +383,24 @@ bool LLControlAvatar::computeNeedsUpdate()
 	computeUpdatePeriod();
 
 	// Animesh attachments are a special case. Should have the same update cadence as their attached parent avatar.
-	bool is_attachment = mRootVolp && mRootVolp->isAttachment(); // For attached animated objects
-	if (is_attachment)
+	LLVOAvatar *attached_av = getAttachedAvatar();
+	if (attached_av)
 	{
-		LLVOAvatar *attached_av = mRootVolp->getAvatarAncestor();
-		if (attached_av)
+		// Have to run computeNeedsUpdate() for attached av in
+		// case it hasn't run updateCharacter() already this
+		// frame.  Note this means that the attached av will
+		// run computeNeedsUpdate() multiple times per frame
+		// if it has animesh attachments. Results will be
+		// consistent except for the corner case of exceeding
+		// MAX_IMPOSTOR_INTERVAL in one call but not another,
+		// which should be rare.
+		attached_av->computeNeedsUpdate();
+		mNeedsImpostorUpdate = attached_av->mNeedsImpostorUpdate;
+		if (mNeedsImpostorUpdate)
 		{
-			// Have to run computeNeedsUpdate() for attached av in
-			// case it hasn't run updateCharacter() already this
-			// frame.  Note this means that the attached av will
-			// run computeNeedsUpdate() multiple times per frame
-			// if it has animesh attachments. Results will be
-			// consistent except for the corner case of exceeding
-			// MAX_IMPOSTOR_INTERVAL in one call but not another,
-			// which should be rare.
-			attached_av->computeNeedsUpdate();
-			mNeedsImpostorUpdate = attached_av->mNeedsImpostorUpdate;
-			if (mNeedsImpostorUpdate)
-			{
-				mLastImpostorUpdateReason = 12;
-			}
-			return mNeedsImpostorUpdate;
+			mLastImpostorUpdateReason = 12;
 		}
+		return mNeedsImpostorUpdate;
 	}
 	return LLVOAvatar::computeNeedsUpdate();
 }
@@ -665,29 +679,23 @@ std::string LLControlAvatar::getFullname() const
 // virtual
 bool LLControlAvatar::shouldRenderRigged() const
 {
-    if (mRootVolp && mRootVolp->isAttachment())
-    {
-        LLVOAvatar *attached_av = mRootVolp->getAvatarAncestor();
-        if (attached_av)
-        {
-            return attached_av->shouldRenderRigged();
-        }
-    }
+	const LLVOAvatar *attached_av = getAttachedAvatar();
+	if (attached_av)
+	{
+		return attached_av->shouldRenderRigged();
+	}
     return true;
 }
 
 // virtual
 BOOL LLControlAvatar::isImpostor()
 {
-    if (mRootVolp && mRootVolp->isAttachment())
-    {
-		// Attached animated objects should match state of their attached av.
-        LLVOAvatar *attached_av = mRootVolp->getAvatarAncestor();
-		if (attached_av)
-		{
-			return attached_av->isImpostor();
-		}
-    }
+	// Attached animated objects should match state of their attached av.
+	LLVOAvatar *attached_av = getAttachedAvatar();
+	if (attached_av)
+	{
+		return attached_av->isImpostor();
+	}
 	return LLVOAvatar::isImpostor();
 }
 
diff --git a/indra/newview/llcontrolavatar.h b/indra/newview/llcontrolavatar.h
index 2c688501403..8e87299f3ee 100644
--- a/indra/newview/llcontrolavatar.h
+++ b/indra/newview/llcontrolavatar.h
@@ -40,6 +40,10 @@ class LLControlAvatar:
 	virtual void 			initInstance(); // Called after construction to initialize the class.
 	virtual	~LLControlAvatar();
 
+	// If this is an attachment, return the avatar it is attached to. Otherwise NULL.
+	virtual const LLVOAvatar *getAttachedAvatar() const;
+	virtual LLVOAvatar *getAttachedAvatar();
+	
     void getNewConstraintFixups(LLVector3& new_pos_constraint, F32& new_scale_constraint) const;
     void matchVolumeTransform();
     void updateVolumeGeom();
diff --git a/indra/newview/lldrawpoolavatar.cpp b/indra/newview/lldrawpoolavatar.cpp
index ff036e19349..e2ca9e40976 100644
--- a/indra/newview/lldrawpoolavatar.cpp
+++ b/indra/newview/lldrawpoolavatar.cpp
@@ -1526,6 +1526,13 @@ void LLDrawPoolAvatar::renderAvatars(LLVOAvatar* single_avatar, S32 pass)
 		return;
 	}
 
+	LLVOAvatar *attached_av = avatarp->getAttachedAvatar();
+	if (attached_av && LLVOAvatar::AOA_NORMAL != attached_av->getOverallAppearance())
+	{
+		// Animesh attachment of a jellydolled or invisible parent - don't show
+		return;
+	}
+
 	if (pass == 0)
 	{
 		if (!LLPipeline::sReflectionRender)
diff --git a/indra/newview/llvoavatar.cpp b/indra/newview/llvoavatar.cpp
index c5bf6ab307b..bf03389310c 100644
--- a/indra/newview/llvoavatar.cpp
+++ b/indra/newview/llvoavatar.cpp
@@ -761,8 +761,8 @@ std::string LLVOAvatar::avString() const
     }
     else
     {
-	std::string viz_string = LLVOAvatar::rezStatusToString(getRezzedStatus());
-	return " Avatar '" + getFullname() + "' " + viz_string + " ";
+		std::string viz_string = LLVOAvatar::rezStatusToString(getRezzedStatus());
+		return " Avatar '" + getFullname() + "' " + viz_string + " ";
     }
 }
 
diff --git a/indra/newview/llvoavatar.h b/indra/newview/llvoavatar.h
index b815b3b2cd2..a30cbc73b73 100644
--- a/indra/newview/llvoavatar.h
+++ b/indra/newview/llvoavatar.h
@@ -132,6 +132,7 @@ class LLVOAvatar :
 public:
 	/*virtual*/ void			updateGL();
 	/*virtual*/ LLVOAvatar*		asAvatar();
+
 	virtual U32    	 	 	processUpdateMessage(LLMessageSystem *mesgsys,
 													 void **user_data,
 													 U32 block_num,
@@ -253,6 +254,11 @@ class LLVOAvatar :
 	virtual bool 	isControlAvatar() const { return mIsControlAvatar; } // True if this avatar is a control av (no associated user)
 	virtual bool 	isUIAvatar() const { return mIsUIAvatar; } // True if this avatar is a supplemental av used in some UI views (no associated user)
 
+	// If this is an attachment, return the avatar it is attached to. Otherwise NULL.
+	virtual const LLVOAvatar *getAttachedAvatar() const { return NULL; }
+	virtual LLVOAvatar *getAttachedAvatar() { return NULL; }
+
+
 private: //aligned members
 	LL_ALIGN_16(LLVector4a	mImpostorExtents[2]);
 
-- 
GitLab