From 9927963ac9d7ef19db96e8d5ffa04c04d0e3b803 Mon Sep 17 00:00:00 2001
From: Logan Dethrow <log@lindenlab.com>
Date: Mon, 1 Apr 2013 20:10:39 -0400
Subject: [PATCH] If we get more caps from a subsequent grant for a region, go
 ahead and use them. This is a hack that should be safe to remove after
 SH-3895 is fixed everywhere on the sim side.

---
 indra/newview/llviewerregion.cpp | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/indra/newview/llviewerregion.cpp b/indra/newview/llviewerregion.cpp
index 223f754c2e8..f4b6ff318b1 100644
--- a/indra/newview/llviewerregion.cpp
+++ b/indra/newview/llviewerregion.cpp
@@ -347,12 +347,23 @@ class BaseCapabilitiesCompleteTracker :  public LLHTTPClient::Responder
 			//	++iter;
 			//}
 
-			regionp->getRegionImplNC()->mSecondCapabilitiesTracker.clear();
+			if (regionp->getRegionImpl()->mSecondCapabilitiesTracker.size() > regionp->getRegionImpl()->mCapabilities.size() )
+			{
+				// *HACK Since we were granted more base capabilities in this grant request than the initial, replace
+				// the old with the new. This shouldn't happen i.e. we should always get the same capabilities from a
+				// sim. The simulator fix from SH-3895 should prevent it from happening, at least in the case of the
+				// inventory api capability grants.
+
+				// Need to clear a std::map before copying into it because old keys take precedence.
+				regionp->getRegionImplNC()->mCapabilities.clear();
+				regionp->getRegionImplNC()->mCapabilities = regionp->getRegionImpl()->mSecondCapabilitiesTracker;
+			}
 		}
 		else
 		{
 			LL_DEBUGS("CrossingCaps") << "Sim sent multiple base cap grants with matching sizes." << LL_ENDL;
 		}
+		regionp->getRegionImplNC()->mSecondCapabilitiesTracker.clear();
 	}
 
 
-- 
GitLab