From e46f66ff31607d7580be3cae3fef9d070b9ba0d0 Mon Sep 17 00:00:00 2001
From: Mnikolenko Productengine <mnikolenko@productengine.com>
Date: Fri, 25 Aug 2017 17:02:33 +0300
Subject: [PATCH] MAINT-7752 FIXED Crash in
 LLPreviewNotecard::handleSaveChangesDialog

---
 indra/newview/llpreview.cpp         |  3 ++-
 indra/newview/llpreview.h           |  3 ++-
 indra/newview/llpreviewgesture.cpp  | 11 ++++++++---
 indra/newview/llpreviewnotecard.cpp | 10 +++++++---
 indra/newview/llpreviewscript.cpp   | 12 +++++++++---
 indra/newview/llpreviewscript.h     |  1 +
 6 files changed, 29 insertions(+), 11 deletions(-)

diff --git a/indra/newview/llpreview.cpp b/indra/newview/llpreview.cpp
index fb21b980dcd..fc2de4844e6 100644
--- a/indra/newview/llpreview.cpp
+++ b/indra/newview/llpreview.cpp
@@ -62,7 +62,8 @@ LLPreview::LLPreview(const LLSD& key)
 	mUserResized(FALSE),
 	mCloseAfterSave(FALSE),
 	mAssetStatus(PREVIEW_ASSET_UNLOADED),
-	mDirty(TRUE)
+	mDirty(TRUE),
+	mSaveDialogShown(FALSE)
 {
 	mAuxItem = new LLInventoryItem;
 	// don't necessarily steal focus on creation -- sometimes these guys pop up without user action
diff --git a/indra/newview/llpreview.h b/indra/newview/llpreview.h
index 49c114720b4..b41aa2be1a6 100644
--- a/indra/newview/llpreview.h
+++ b/indra/newview/llpreview.h
@@ -121,7 +121,8 @@ class LLPreview : public LLFloater, LLInventoryObserver
 	// for LLInventoryObserver 
 	virtual void changed(U32 mask);	
 	BOOL mDirty;
-	
+	BOOL mSaveDialogShown;
+
 protected:
 	LLUUID mItemUUID;
 
diff --git a/indra/newview/llpreviewgesture.cpp b/indra/newview/llpreviewgesture.cpp
index ff9a70d05c9..787bd68e589 100644
--- a/indra/newview/llpreviewgesture.cpp
+++ b/indra/newview/llpreviewgesture.cpp
@@ -234,9 +234,13 @@ BOOL LLPreviewGesture::canClose()
 	}
 	else
 	{
-		// Bring up view-modal dialog: Save changes? Yes, No, Cancel
-		LLNotificationsUtil::add("SaveChanges", LLSD(), LLSD(),
-			boost::bind(&LLPreviewGesture::handleSaveChangesDialog, this, _1, _2) );
+		if(!mSaveDialogShown)
+		{
+			mSaveDialogShown = TRUE;
+			// Bring up view-modal dialog: Save changes? Yes, No, Cancel
+			LLNotificationsUtil::add("SaveChanges", LLSD(), LLSD(),
+					boost::bind(&LLPreviewGesture::handleSaveChangesDialog, this, _1, _2) );
+		}
 		return FALSE;
 	}
 }
@@ -264,6 +268,7 @@ void LLPreviewGesture::onVisibilityChanged ( const LLSD& new_visibility )
 
 bool LLPreviewGesture::handleSaveChangesDialog(const LLSD& notification, const LLSD& response)
 {
+	mSaveDialogShown = FALSE;
 	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
 	switch(option)
 	{
diff --git a/indra/newview/llpreviewnotecard.cpp b/indra/newview/llpreviewnotecard.cpp
index 510d91839d6..850c3b350dc 100644
--- a/indra/newview/llpreviewnotecard.cpp
+++ b/indra/newview/llpreviewnotecard.cpp
@@ -153,9 +153,12 @@ BOOL LLPreviewNotecard::canClose()
 	}
 	else
 	{
-		// Bring up view-modal dialog: Save changes? Yes, No, Cancel
-		LLNotificationsUtil::add("SaveChanges", LLSD(), LLSD(), boost::bind(&LLPreviewNotecard::handleSaveChangesDialog,this, _1, _2));
-								  
+		if(!mSaveDialogShown)
+		{
+			mSaveDialogShown = TRUE;
+			// Bring up view-modal dialog: Save changes? Yes, No, Cancel
+			LLNotificationsUtil::add("SaveChanges", LLSD(), LLSD(), boost::bind(&LLPreviewNotecard::handleSaveChangesDialog,this, _1, _2));
+		}
 		return FALSE;
 	}
 }
@@ -639,6 +642,7 @@ void LLPreviewNotecard::onSaveComplete(const LLUUID& asset_uuid, void* user_data
 
 bool LLPreviewNotecard::handleSaveChangesDialog(const LLSD& notification, const LLSD& response)
 {
+	mSaveDialogShown = FALSE;
 	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
 	switch(option)
 	{
diff --git a/indra/newview/llpreviewscript.cpp b/indra/newview/llpreviewscript.cpp
index 3c5e2544bb5..2476b6d6ed4 100644
--- a/indra/newview/llpreviewscript.cpp
+++ b/indra/newview/llpreviewscript.cpp
@@ -376,7 +376,8 @@ LLScriptEdCore::LLScriptEdCore(
 	mLive(live),
 	mContainer(container),
 	mHasScriptData(FALSE),
-	mScriptRemoved(FALSE)
+	mScriptRemoved(FALSE),
+	mSaveDialogShown(FALSE)
 {
 	setFollowsAll();
 	setBorderVisible(FALSE);
@@ -855,8 +856,12 @@ BOOL LLScriptEdCore::canClose()
 	}
 	else
 	{
-		// Bring up view-modal dialog: Save changes? Yes, No, Cancel
-		LLNotificationsUtil::add("SaveChanges", LLSD(), LLSD(), boost::bind(&LLScriptEdCore::handleSaveChangesDialog, this, _1, _2));
+		if(!mSaveDialogShown)
+		{
+			mSaveDialogShown = TRUE;
+			// Bring up view-modal dialog: Save changes? Yes, No, Cancel
+			LLNotificationsUtil::add("SaveChanges", LLSD(), LLSD(), boost::bind(&LLScriptEdCore::handleSaveChangesDialog, this, _1, _2));
+		}
 		return FALSE;
 	}
 }
@@ -869,6 +874,7 @@ void LLScriptEdCore::setEnableEditing(bool enable)
 
 bool LLScriptEdCore::handleSaveChangesDialog(const LLSD& notification, const LLSD& response )
 {
+	mSaveDialogShown = FALSE;
 	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
 	switch( option )
 	{
diff --git a/indra/newview/llpreviewscript.h b/indra/newview/llpreviewscript.h
index 8178bb93258..a185d858898 100644
--- a/indra/newview/llpreviewscript.h
+++ b/indra/newview/llpreviewscript.h
@@ -167,6 +167,7 @@ class LLScriptEdCore : public LLPanel
 	LLLiveLSLFile*	mLiveFile;
 	LLUUID			mAssociatedExperience;
 	BOOL			mScriptRemoved;
+	BOOL			mSaveDialogShown;
 
 	LLScriptEdContainer* mContainer; // parent view
 
-- 
GitLab