From a9871e8d258404ff32956b093c80b4cf56c3522c Mon Sep 17 00:00:00 2001
From: "Brad Payne (Vir Linden)" <vir@lindenlab.com>
Date: Wed, 20 Jan 2010 17:59:16 -0500
Subject: [PATCH] For EXT-4222: Switching outfits sometimes causes me to wear
 both, and show previous outfit as worn.

---
 indra/newview/llappearancemgr.cpp | 29 +++++++++++++++++++++--------
 1 file changed, 21 insertions(+), 8 deletions(-)

diff --git a/indra/newview/llappearancemgr.cpp b/indra/newview/llappearancemgr.cpp
index 0d4e048ddea..ccda737fc62 100644
--- a/indra/newview/llappearancemgr.cpp
+++ b/indra/newview/llappearancemgr.cpp
@@ -301,6 +301,7 @@ class LLWearableHoldingPattern
 
 	bool pollCompletion();
 	bool isDone();
+	bool isTimedOut();
 	
 	typedef std::list<LLFoundData> found_list_t;
 	found_list_t mFoundList;
@@ -313,12 +314,10 @@ class LLWearableHoldingPattern
 LLWearableHoldingPattern::LLWearableHoldingPattern():
 	mResolved(0)
 {
-	llwarns << "constructor" << llendl;
 }
 
 LLWearableHoldingPattern::~LLWearableHoldingPattern()
 {
-	llwarns << "destructor" << llendl;
 }
 
 bool LLWearableHoldingPattern::isDone()
@@ -326,10 +325,16 @@ bool LLWearableHoldingPattern::isDone()
 	return (mResolved >= (S32)mFoundList.size());
 }
 
+bool LLWearableHoldingPattern::isTimedOut()
+{
+	static F32 max_wait_time = 5.0;  // give up if wearable fetches haven't completed in max_wait_time seconds.
+	return mWaitTime.getElapsedTimeF32() > max_wait_time; 
+}
+
 bool LLWearableHoldingPattern::pollCompletion()
 {
 	bool done = isDone();
-	llwarns << "polling, done status: " << done << llendl;
+	llinfos << "polling, done status: " << done << llendl;
 	if (done)
 	{
 		// Activate all gestures in this folder
@@ -350,6 +355,10 @@ bool LLWearableHoldingPattern::pollCompletion()
 				gInventory.notifyObservers();
 			}
 		}
+
+		// Update wearables.
+		llinfos << "Updating agent wearables with " << mResolved << " wearable items " << llendl;
+		LLAppearanceManager::instance().updateAgentWearables(this, false);
 		
 		// Update attachments to match those requested.
 		LLVOAvatar* avatar = gAgent.getAvatarObject();
@@ -359,13 +368,17 @@ bool LLWearableHoldingPattern::pollCompletion()
 			LLAgentWearables::userUpdateAttachments(mObjItems);
 		}
 
-		// Update wearables.
-		llinfos << "Updating agent wearables with " << mResolved << " wearable items " << llendl;
-		LLAppearanceManager::instance().updateAgentWearables(this, false);
-
 		delete this;
+		return done;
+	}
+	else if (isTimedOut())
+	{
+		llwarns << "wearables taking too long to fetch for outfit, retrying updateAppearanceFromCOF()." << llendl;
+		delete this;
+		LLAppearanceManager::instance().updateAppearanceFromCOF();
+		return true;
 	}
-	return done;
+	return false;
 }
 
 static void removeDuplicateItems(LLInventoryModel::item_array_t& items)
-- 
GitLab