From 8f51459a2e7b1d836dc25f82604834e7dd8efd6a Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@alchemyviewer.org>
Date: Fri, 13 Mar 2020 07:24:09 -0400
Subject: [PATCH] Some fixes to mesh skin info load

---
 indra/newview/llmeshrepository.cpp |  2 +-
 indra/newview/llmeshrepository.h   |  2 +-
 indra/newview/llvoavatar.cpp       |  4 ++--
 indra/newview/llvovolume.cpp       | 21 ++++-----------------
 indra/newview/llvovolume.h         |  8 +++-----
 5 files changed, 11 insertions(+), 26 deletions(-)

diff --git a/indra/newview/llmeshrepository.cpp b/indra/newview/llmeshrepository.cpp
index 9f9f564ba6..da087786c9 100644
--- a/indra/newview/llmeshrepository.cpp
+++ b/indra/newview/llmeshrepository.cpp
@@ -4076,7 +4076,7 @@ S32 LLMeshRepository::getActualMeshLOD(const LLVolumeParams& mesh_params, S32 lo
 
 static LLFastTimer::DeclareTimer FTM_MESH_FETCH_GET_SKIN_INFO("Get Skin Info");
 static LLFastTimer::DeclareTimer FTM_MESH_FETCH_GET_SKIN_INFO_FETCH("Get Skin Info Fetch");
-LLMeshSkinInfo* LLMeshRepository::getSkinInfo(const LLUUID& mesh_id, LLVOVolume* requesting_obj)
+const LLMeshSkinInfo* LLMeshRepository::getSkinInfo(const LLUUID& mesh_id, LLVOVolume* requesting_obj)
 {
 	LL_RECORD_BLOCK_TIME(FTM_MESH_FETCH);
 	LL_RECORD_BLOCK_TIME(FTM_MESH_FETCH_GET_SKIN_INFO);
diff --git a/indra/newview/llmeshrepository.h b/indra/newview/llmeshrepository.h
index 8e9f37afc1..77f02fcf91 100644
--- a/indra/newview/llmeshrepository.h
+++ b/indra/newview/llmeshrepository.h
@@ -597,7 +597,7 @@ public:
 
 	S32 getActualMeshLOD(const LLVolumeParams& mesh_params, S32 lod);
 	static S32 getActualMeshLOD(LLSD& header, S32 lod);
-	LLMeshSkinInfo* getSkinInfo(const LLUUID& mesh_id, LLVOVolume* requesting_obj);
+	const LLMeshSkinInfo* getSkinInfo(const LLUUID& mesh_id, LLVOVolume* requesting_obj);
 	LLModel::Decomposition* getDecomposition(const LLUUID& mesh_id);
 	void fetchPhysicsShape(const LLUUID& mesh_id);
 	bool hasPhysicsShape(const LLUUID& mesh_id);
diff --git a/indra/newview/llvoavatar.cpp b/indra/newview/llvoavatar.cpp
index 0948199385..a162f48374 100644
--- a/indra/newview/llvoavatar.cpp
+++ b/indra/newview/llvoavatar.cpp
@@ -6362,7 +6362,7 @@ void LLVOAvatar::addAttachmentOverridesForObject(LLViewerObject *vo, std::set<LL
 
 	LLViewerObject *root_object = (LLViewerObject*)vobj->getRoot();
     LL_DEBUGS("AnimatedObjects") << "trying to add attachment overrides for root object " << root_object->getID() << " prim is " << vobj << LL_ENDL;
-	if (vobj->isRiggedMesh() &&
+	if (vobj->isMesh() &&
 		((vobj->getVolume() && !vobj->getVolume()->isMeshAssetLoaded()) || !gMeshRepo.meshRezEnabled()))
 	{
         LL_DEBUGS("AnimatedObjects") << "failed to add attachment overrides for root object " << root_object->getID() << " mesh asset not loaded" << LL_ENDL;
@@ -6370,7 +6370,7 @@ void LLVOAvatar::addAttachmentOverridesForObject(LLViewerObject *vo, std::set<LL
 	}
 	const LLMeshSkinInfo*  pSkinData = nullptr;
 
-	if ( vobj && vobj->isMesh() && (pSkinData = vobj->getSkinInfo()) )
+	if ( vobj && vobj->isMesh() && (pSkinData = vobj->getSkinInfo()) && vobj->getVolume() && vobj->getVolume()->isMeshAssetLoaded() && gMeshRepo.meshRezEnabled())
 	{
 		const size_t bindCnt = pSkinData->mAlternateBindMatrix.size();								
         const size_t jointCnt = pSkinData->mJointNames.size();
diff --git a/indra/newview/llvovolume.cpp b/indra/newview/llvovolume.cpp
index 14dd17912b..9b7280c8e2 100644
--- a/indra/newview/llvovolume.cpp
+++ b/indra/newview/llvovolume.cpp
@@ -237,7 +237,6 @@ LLVOVolume::LLVOVolume(const LLUUID &id, const LLPCode pcode, LLViewerRegion *re
 	mSculptChanged = FALSE;
 	mSpotLightPriority = 0.f;
 
-	mSkinInfoReceived = false;
 	mSkinInfoFailed = false;
 	mSkinInfo = NULL;
 
@@ -1064,7 +1063,6 @@ BOOL LLVOVolume::setVolume(const LLVolumeParams &params_in, const S32 detail, bo
 				if (mSkinInfo && mSkinInfo->mMeshID != volume_params.getSculptID())
 				{
 					mSkinInfo = NULL;
-					mSkinInfoReceived = false;
 					mSkinInfoFailed = false;
 				}
 
@@ -1078,7 +1076,7 @@ BOOL LLVOVolume::setVolume(const LLVolumeParams &params_in, const S32 detail, bo
 					}
 				}
 				
-				if (!mSkinInfo && !isSkinInfoLoaded() && !hasSkinInfoFailed())
+				if (!mSkinInfo && !hasSkinInfoFailed())
 				{
 					mSkinInfo = gMeshRepo.getSkinInfo(volume_params.getSculptID(), this);
 					if (mSkinInfo)
@@ -1119,6 +1117,7 @@ void LLVOVolume::updateSculptTexture()
 			mSculptTexture = LLViewerTextureManager::getFetchedTexture(id, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE);
 		}
 
+		mSkinInfoFailed = false;
 		mSkinInfo = NULL;
 	}
 	else
@@ -1170,29 +1169,17 @@ void LLVOVolume::notifyMeshLoaded()
     updateVisualComplexity();
 }
 
-void LLVOVolume::notifySkinInfoLoaded(LLMeshSkinInfo* skin)
+void LLVOVolume::notifySkinInfoLoaded(const LLMeshSkinInfo* skin)
 {
 	mSkinInfoFailed = false;
-	mSkinInfoReceived = true;
 	mSkinInfo = skin;
 
-	mSculptChanged = TRUE;
-	gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_RIGGED, TRUE);
-
-	if (getAvatar() && !isAnimatedObject())
-	{
-		getAvatar()->addAttachmentOverridesForObject(this);
-	}
-	if (getControlAvatar() && isAnimatedObject())
-	{
-		getControlAvatar()->addAttachmentOverridesForObject(this);
-	}
+	notifyMeshLoaded();
 }
 
 void LLVOVolume::notifySkinInfoUnavailable()
 {
 	mSkinInfoFailed = true;
-	mSkinInfoReceived = false;
 	mSkinInfo = nullptr;
 }
 
diff --git a/indra/newview/llvovolume.h b/indra/newview/llvovolume.h
index b45be1823a..11dbf8ecd5 100644
--- a/indra/newview/llvovolume.h
+++ b/indra/newview/llvovolume.h
@@ -334,7 +334,7 @@ public:
     void updateVisualComplexity();
     
 	void notifyMeshLoaded();
-	void notifySkinInfoLoaded(LLMeshSkinInfo* skin);
+	void notifySkinInfoLoaded(const LLMeshSkinInfo* skin);
 	void notifySkinInfoUnavailable();
 	
 	// Returns 'true' iff the media data for this object is in flight
@@ -414,12 +414,10 @@ private:
 
 	LLPointer<LLRiggedVolume> mRiggedVolume;
 
-	bool isSkinInfoLoaded() { return mSkinInfoReceived; }
-	bool hasSkinInfoFailed() { return mSkinInfoFailed; }
+	bool hasSkinInfoFailed() const { return mSkinInfoFailed; }
 
-	bool mSkinInfoReceived;
 	bool mSkinInfoFailed;
-	LLMeshSkinInfo *mSkinInfo;
+	const LLMeshSkinInfo *mSkinInfo;
 	
 	// statics
 public:
-- 
GitLab