From 8ba0baa63109d5e45c1f3cfd75c7d230ff99031f Mon Sep 17 00:00:00 2001
From: Xiaohong Bao <bao@lindenlab.com>
Date: Wed, 22 Dec 2010 10:55:48 -0700
Subject: fix for SH-648: Crash on exit in LLViewerFetchedTexture (ref count
 error)

---
 indra/newview/llappviewer.cpp           |  1 +
 indra/newview/llfloatermodelpreview.cpp |  8 ++++----
 indra/newview/llfloatermodelpreview.h   |  2 +-
 indra/newview/llmeshrepository.cpp      | 25 +++++++++++++++++++++----
 indra/newview/llmeshrepository.h        |  6 ++++--
 5 files changed, 31 insertions(+), 11 deletions(-)

(limited to 'indra')

diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp
index 08f5cb4685..0ff4336f4c 100644
--- a/indra/newview/llappviewer.cpp
+++ b/indra/newview/llappviewer.cpp
@@ -1262,6 +1262,7 @@ bool LLAppViewer::mainLoop()
 						break;
 					}
 				}
+				gMeshRepo.update() ;
 
 				if(!total_work_pending) //pause texture fetching threads if nothing to process.
 				{
diff --git a/indra/newview/llfloatermodelpreview.cpp b/indra/newview/llfloatermodelpreview.cpp
index 85d0ae02cf..cc4359a1bf 100755
--- a/indra/newview/llfloatermodelpreview.cpp
+++ b/indra/newview/llfloatermodelpreview.cpp
@@ -475,10 +475,10 @@ void LLFloaterModelPreview::onPreviewLODCommit(LLUICtrl* ctrl, void* userdata)
 	
 	S32 which_mode = 0;
 	
-	LLComboBox* combo = (LLComboBox*) ctrl;
-	
-	which_mode = (NUM_LOD-1)-combo->getFirstSelectedIndex(); // combo box list of lods is in reverse order
-
+	LLComboBox* combo = (LLComboBox*) ctrl;
+	
+	which_mode = (NUM_LOD-1)-combo->getFirstSelectedIndex(); // combo box list of lods is in reverse order
+
 	fp->mModelPreview->setPreviewLOD(which_mode);
 }
 
diff --git a/indra/newview/llfloatermodelpreview.h b/indra/newview/llfloatermodelpreview.h
index 64b220d86b..623cd286fb 100644
--- a/indra/newview/llfloatermodelpreview.h
+++ b/indra/newview/llfloatermodelpreview.h
@@ -52,7 +52,7 @@ class domTranslate;
 class LLMenuButton;
 class LLToggleableMenu;
 
-const S32 NUM_LOD = 4;
+const S32 NUM_LOD = 4;
 
 class LLModelLoader : public LLThread
 {
diff --git a/indra/newview/llmeshrepository.cpp b/indra/newview/llmeshrepository.cpp
index 4873eaeabd..2815054865 100755
--- a/indra/newview/llmeshrepository.cpp
+++ b/indra/newview/llmeshrepository.cpp
@@ -1486,7 +1486,7 @@ void LLMeshUploadThread::run()
 				{
 					textures.insert(material_iter->mDiffuseMap);
 					
-					LLTextureUploadData data(material_iter->mDiffuseMap, material_iter->mDiffuseMapLabel);
+					LLTextureUploadData data(material_iter->mDiffuseMap.get(), material_iter->mDiffuseMapLabel);
 					uploadTexture(data);
 				}
 			}
@@ -2135,6 +2135,24 @@ void LLMeshRepository::shutdown()
 	LLConvexDecomposition::quitSystem();
 }
 
+//called in the main thread.
+S32 LLMeshRepository::update()
+{
+	if(mUploadWaitList.empty())
+	{
+		return 0 ;
+	}
+
+	S32 size = mUploadWaitList.size() ;
+	for (S32 i = 0; i < size; ++i)
+	{
+		mUploads.push_back(mUploadWaitList[i]);
+		mUploadWaitList[i]->start() ;
+	}
+	mUploadWaitList.clear() ;
+
+	return size ;
+}
 
 S32 LLMeshRepository::loadMesh(LLVOVolume* vobj, const LLVolumeParams& mesh_params, S32 detail)
 {
@@ -2654,8 +2672,7 @@ void LLMeshRepository::uploadModel(std::vector<LLModelInstance>& data, LLVector3
 									bool upload_skin, bool upload_joints)
 {
 	LLMeshUploadThread* thread = new LLMeshUploadThread(data, scale, upload_textures, upload_skin, upload_joints);
-	mUploads.push_back(thread);
-	thread->start();
+	mUploadWaitList.push_back(thread);
 }
 
 S32 LLMeshRepository::getMeshSize(const LLUUID& mesh_id, S32 lod)
@@ -2742,7 +2759,7 @@ void LLMeshUploadThread::sendCostRequest(LLMeshUploadData& data)
 
 void LLMeshUploadThread::sendCostRequest(LLTextureUploadData& data)
 {
-	if (data.mTexture.notNull() && data.mTexture->getDiscardLevel() >= 0)
+	if (data.mTexture && data.mTexture->getDiscardLevel() >= 0)
 	{
 		LLSD asset_resources = LLSD::emptyMap();
 
diff --git a/indra/newview/llmeshrepository.h b/indra/newview/llmeshrepository.h
index 8687ac750b..0926a94ec2 100644
--- a/indra/newview/llmeshrepository.h
+++ b/indra/newview/llmeshrepository.h
@@ -65,7 +65,7 @@ public:
 class LLTextureUploadData
 {
 public:
-	LLPointer<LLViewerFetchedTexture> mTexture;
+	LLViewerFetchedTexture* mTexture;
 	LLUUID mUUID;
 	std::string mRSVP;
 	std::string mLabel;
@@ -399,7 +399,7 @@ public:
 	std::queue<LLTextureUploadData> mTextureQ;
 	std::queue<LLTextureUploadData> mConfirmedTextureQ;
 
-	std::map<LLPointer<LLViewerFetchedTexture>, LLTextureUploadData> mTextureMap;
+	std::map<LLViewerFetchedTexture*, LLTextureUploadData> mTextureMap;
 
 	LLMeshUploadThread(instance_list& data, LLVector3& scale, bool upload_textures,
 			bool upload_skin, bool upload_joints);
@@ -442,6 +442,7 @@ public:
 
 	void init();
 	void shutdown();
+	S32 update() ;
 
 	//mesh management functions
 	S32 loadMesh(LLVOVolume* volume, const LLVolumeParams& mesh_params, S32 detail = 0);
@@ -505,6 +506,7 @@ public:
 	
 	LLMeshRepoThread* mThread;
 	std::vector<LLMeshUploadThread*> mUploads;
+	std::vector<LLMeshUploadThread*> mUploadWaitList;
 
 	LLPhysicsDecomp* mDecompThread;
 	
-- 
cgit v1.2.3