From b5b0c174390b4158c69eeff7efd59c4f1615e491 Mon Sep 17 00:00:00 2001
From: Andrey Kleshchev <andreykproductengine@lindenlab.com>
Date: Sat, 17 Jun 2023 01:31:02 +0300
Subject: SL-19886 Fix onidle crash after closing inventory floater

---
 indra/llcommon/llcallbacklist.cpp    |  2 +-
 indra/newview/llinventorygallery.cpp | 12 ++++++++----
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/indra/llcommon/llcallbacklist.cpp b/indra/llcommon/llcallbacklist.cpp
index 93d0a035da..9f23ce5317 100644
--- a/indra/llcommon/llcallbacklist.cpp
+++ b/indra/llcommon/llcallbacklist.cpp
@@ -55,7 +55,7 @@ void LLCallbackList::addFunction( callback_t func, void *data)
 
 	// only add one callback per func/data pair
 	//
-	if (containsFunction(func))
+	if (containsFunction(func, data))
 	{
 		return;
 	}
diff --git a/indra/newview/llinventorygallery.cpp b/indra/newview/llinventorygallery.cpp
index f81beefc28..cfaff512ff 100644
--- a/indra/newview/llinventorygallery.cpp
+++ b/indra/newview/llinventorygallery.cpp
@@ -143,8 +143,8 @@ LLInventoryGallery::~LLInventoryGallery()
     delete mInventoryGalleryMenu;
     delete mRootGalleryMenu;
     delete mFilter;
-    
-    gIdleCallbacks.deleteFunction(onIdle, this);
+
+    gIdleCallbacks.deleteFunction(onIdle, (void*)this);
 
     while (!mUnusedRowPanels.empty())
     {
@@ -184,8 +184,6 @@ LLInventoryGallery::~LLInventoryGallery()
 
 void LLInventoryGallery::setRootFolder(const LLUUID cat_id)
 {
-    gIdleCallbacks.deleteFunction(onIdle, this);
-
     LLViewerInventoryCategory* category = gInventory.getCategory(cat_id);
     if(!category || (mFolderID == cat_id))
     {
@@ -195,7 +193,13 @@ void LLInventoryGallery::setRootFolder(const LLUUID cat_id)
     {
         mBackwardFolders.push_back(mFolderID);
     }
+
+    gIdleCallbacks.deleteFunction(onIdle, (void*)this);
+
     mFolderID = cat_id;
+    mItemToSelect.setNull();
+    mItemBuildQuery.clear();
+    mNeedsArrange = false;
     dirtyRootFolder();
 }
 
-- 
cgit v1.2.3