From 3a25753bcf46cc8d36bcf3d3bf21d9d0d94dbd34 Mon Sep 17 00:00:00 2001
From: Aaron Stone <stone@lindenlab.com>
Date: Fri, 17 Jun 2011 16:16:01 -0700
Subject: [PATCH] STORM-1368 Code more defensively around notecard upload.

---
 indra/newview/llpreviewnotecard.cpp | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/indra/newview/llpreviewnotecard.cpp b/indra/newview/llpreviewnotecard.cpp
index 9f3ee6ac5d2..4974dde282c 100644
--- a/indra/newview/llpreviewnotecard.cpp
+++ b/indra/newview/llpreviewnotecard.cpp
@@ -401,15 +401,14 @@ struct LLSaveNotecardInfo
 
 bool LLPreviewNotecard::saveIfNeeded(LLInventoryItem* copyitem)
 {
-	if(!gAssetStorage)
+	LLViewerTextEditor* editor = getChild<LLViewerTextEditor>("Notecard Editor");
+
+	if(!editor)
 	{
-		llwarns << "Not connected to an asset storage system." << llendl;
+		llwarns << "Cannot get handle to the notecard editor." << llendl;
 		return false;
 	}
 
-	
-	LLViewerTextEditor* editor = getChild<LLViewerTextEditor>("Notecard Editor");
-
 	if(!editor->isPristine())
 	{
 		// We need to update the asset information
@@ -436,8 +435,15 @@ bool LLPreviewNotecard::saveIfNeeded(LLInventoryItem* copyitem)
 		// save it out to database
 		if (item)
 		{			
-			std::string agent_url = gAgent.getRegion()->getCapability("UpdateNotecardAgentInventory");
-			std::string task_url = gAgent.getRegion()->getCapability("UpdateNotecardTaskInventory");
+			const LLViewerRegion* region = gAgent.getRegion();
+			if (!region)
+			{
+				llwarns << "Not connected to a region, cannot save notecard." << llendl;
+				return false;
+			}
+			std::string agent_url = region->getCapability("UpdateNotecardAgentInventory");
+			std::string task_url = region->getCapability("UpdateNotecardTaskInventory");
+
 			if (mObjectUUID.isNull() && !agent_url.empty())
 			{
 				// Saving into agent inventory
@@ -472,6 +478,11 @@ bool LLPreviewNotecard::saveIfNeeded(LLInventoryItem* copyitem)
 												(void*)info,
 												FALSE);
 			}
+			else // !gAssetStorage
+			{
+				llwarns << "Not connected to an asset storage system." << llendl;
+				return false;
+			}
 		}
 	}
 	return true;
-- 
GitLab