From 984353d7ca6184d7252c716150d42139aae94e5c Mon Sep 17 00:00:00 2001
From: Cinder <cinder.roxley@phoenixviewer.com>
Date: Fri, 20 Jun 2014 11:02:50 -0600
Subject: [PATCH] STORM-2036 - Fix trying to parse caps too early by adding a
 callback to check region caps when they haven't already been received

---
 doc/contributions.txt        |  1 +
 indra/newview/llsyntaxid.cpp | 19 +++++++++++++++----
 indra/newview/llsyntaxid.h   |  1 +
 3 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/doc/contributions.txt b/doc/contributions.txt
index a3ca5d5f58e..3ba4ee89739 100755
--- a/doc/contributions.txt
+++ b/doc/contributions.txt
@@ -321,6 +321,7 @@ Cinder Roxley
     STORM-1958
     STORM-1952
     STORM-1951
+    STORM-2036
 Clara Young
 Coaldust Numbers
     VWR-1095
diff --git a/indra/newview/llsyntaxid.cpp b/indra/newview/llsyntaxid.cpp
index 9b827101613..b1194dcd1ba 100644
--- a/indra/newview/llsyntaxid.cpp
+++ b/indra/newview/llsyntaxid.cpp
@@ -128,7 +128,6 @@ void LLSyntaxIdLSL::buildFullFileSpec()
 //-----------------------------------------------------------------------------
 bool LLSyntaxIdLSL::syntaxIdChanged()
 {
-	bool version_changed = false;
 	LLViewerRegion* region = gAgent.getRegion();
 
 	if (region)
@@ -148,7 +147,7 @@ bool LLSyntaxIdLSL::syntaxIdChanged()
 				{
 					LL_DEBUGS("SyntaxLSL") << "New SyntaxID '" << new_syntax_id << "' found." << LL_ENDL;
 					mSyntaxId = new_syntax_id;
-					version_changed = true;
+					return true;
 				}
 				else
 					LL_DEBUGS("SyntaxLSL") << "SyntaxID matches what we have." << LL_ENDL;
@@ -156,10 +155,11 @@ bool LLSyntaxIdLSL::syntaxIdChanged()
 		}
 		else
 		{
-			LL_WARNS("SyntaxLSL") << "Region '" << region->getName() << "' has not received capabilities. Cannot process SyntaxId." << LL_ENDL;
+			region->setCapabilitiesReceivedCallback(boost::bind(&LLSyntaxIdLSL::handleCapsReceived, this, _1));
+			LL_DEBUGS("SyntaxLSL") << "Region has not received capabilities. Waiting for caps..." << LL_ENDL;
 		}
 	}
-	return version_changed;
+	return false;
 }
 
 //-----------------------------------------------------------------------------
@@ -307,6 +307,17 @@ void LLSyntaxIdLSL::handleRegionChanged()
 	}
 }
 
+void LLSyntaxIdLSL::handleCapsReceived(const LLUUID& region_uuid)
+{
+	LLViewerRegion* current_region = gAgent.getRegion();
+	
+	if (region_uuid.notNull()
+		&& current_region->getRegionID() == region_uuid)
+	{
+		syntaxIdChanged();
+	}
+}
+
 void LLSyntaxIdLSL::handleFileFetched(const std::string& filepath)
 {
 	mInflightFetches.remove(filepath);
diff --git a/indra/newview/llsyntaxid.h b/indra/newview/llsyntaxid.h
index 70f6b283378..504fb0997e1 100644
--- a/indra/newview/llsyntaxid.h
+++ b/indra/newview/llsyntaxid.h
@@ -48,6 +48,7 @@ class LLSyntaxIdLSL : public LLSingleton<LLSyntaxIdLSL>
 	bool	syntaxIdChanged();
 	bool	isSupportedVersion(const LLSD& content);
 	void	handleRegionChanged();
+	void	handleCapsReceived(const LLUUID& region_uuid);
 	void	handleFileFetched(const std::string& filepath);
 	void	setKeywordsXml(const LLSD& content) { mKeywordsXml = content; };
 	void	buildFullFileSpec();
-- 
GitLab