From fed874689592d969ede984daa75b470ddf182d77 Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@alchemyviewer.org>
Date: Fri, 26 Jan 2024 15:57:55 -0500
Subject: [PATCH] Fix classified observer crash

---
 indra/newview/llavatarpropertiesprocessor.cpp | 2 +-
 indra/newview/llfloaterpreference.cpp         | 8 +++-----
 indra/newview/llpanelclassified.cpp           | 5 +++++
 indra/newview/llpanelprofileclassifieds.cpp   | 7 ++++++-
 4 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/indra/newview/llavatarpropertiesprocessor.cpp b/indra/newview/llavatarpropertiesprocessor.cpp
index 74af7cdf4c1..faaa09332c1 100644
--- a/indra/newview/llavatarpropertiesprocessor.cpp
+++ b/indra/newview/llavatarpropertiesprocessor.cpp
@@ -175,7 +175,7 @@ void LLAvatarPropertiesProcessor::initAgentProfileCapRequest(const LLUUID& avata
     addPendingRequest(avatar_id, APT_PICKS);
     addPendingRequest(avatar_id, APT_GROUPS);
     addPendingRequest(avatar_id, APT_NOTES);
-    LLCoros::instance().launch("requestAgentUserInfoCoro",
+    LLCoros::instance().launch("requestAvatarPropertiesCoro",
         boost::bind(requestAvatarPropertiesCoro, cap_url, avatar_id));
 }
 
diff --git a/indra/newview/llfloaterpreference.cpp b/indra/newview/llfloaterpreference.cpp
index cb466bbb9d3..5678975830c 100644
--- a/indra/newview/llfloaterpreference.cpp
+++ b/indra/newview/llfloaterpreference.cpp
@@ -357,7 +357,7 @@ LLFloaterPreference::LLFloaterPreference(const LLSD& key)
 
 	mCommitCallbackRegistrar.add("Pref.ClickActionChange",		boost::bind(&LLFloaterPreference::onClickActionChange, this));
 
-	LLAvatarPropertiesProcessor::getInstance()->addObserver( gAgent.getID(), this );
+	LLAvatarPropertiesProcessor::getInstance()->addObserver(LLUUID::null, this);
 
     mComplexityChangedSignal = gSavedSettings.getControl("RenderAvatarMaxComplexity")->getCommitSignal()->connect(boost::bind(&LLFloaterPreference::updateComplexityText, this));
 
@@ -406,7 +406,7 @@ void LLFloaterPreference::saveAvatarProperties( void )
         {
             mAllowPublish = allowPublish;
 
-            LLCoros::instance().launch("requestAgentUserInfoCoro",
+            LLCoros::instance().launch("saveAvatarPropertiesCoro",
                 boost::bind(saveAvatarPropertiesCoro, cap_url, allowPublish));
         }
     }
@@ -918,7 +918,7 @@ LLFloaterPreference::~LLFloaterPreference()
 	if (mGridListChangedConnection.connected())
 		mGridListChangedConnection.disconnect();
 #endif
-	LLAvatarPropertiesProcessor::getInstance()->removeObserver(gAgent.getID(), this);
+	LLAvatarPropertiesProcessor::getInstance()->removeObserver(LLUUID::null, this);
 	LLConversationLog::instance().removeObserver(this);
     mComplexityChangedSignal.disconnect();
 	mDnDModeConnection.disconnect();
@@ -952,8 +952,6 @@ void LLFloaterPreference::saveSettings()
 
 void LLFloaterPreference::apply()
 {
-	LLAvatarPropertiesProcessor::getInstance()->addObserver( gAgent.getID(), this );
-	
 	LLTabContainer* tabcontainer = getChild<LLTabContainer>("pref core");
 	if (sSkin != gSavedSettings.getString("SkinCurrent"))
 	{
diff --git a/indra/newview/llpanelclassified.cpp b/indra/newview/llpanelclassified.cpp
index a629d2b00a7..27fd2e11112 100644
--- a/indra/newview/llpanelclassified.cpp
+++ b/indra/newview/llpanelclassified.cpp
@@ -116,6 +116,10 @@ LLPanelClassifiedInfo::LLPanelClassifiedInfo()
 
 LLPanelClassifiedInfo::~LLPanelClassifiedInfo()
 {
+	if (getAvatarId().notNull())
+	{
+		LLAvatarPropertiesProcessor::getInstance()->removeObserver(getAvatarId(), this);
+	}
 	sAllPanels.remove(this);
 }
 
@@ -207,6 +211,7 @@ void LLPanelClassifiedInfo::onOpen(const LLSD& key)
 
 	LLAvatarPropertiesProcessor::getInstance()->addObserver(getAvatarId(), this);
 	LLAvatarPropertiesProcessor::getInstance()->sendClassifiedInfoRequest(getClassifiedId());
+
 	gGenericDispatcher.addHandler("classifiedclickthrough", &sClassifiedClickThrough);
 
 	if (gAgent.getRegion())
diff --git a/indra/newview/llpanelprofileclassifieds.cpp b/indra/newview/llpanelprofileclassifieds.cpp
index 72303a2da21..de981d37c00 100644
--- a/indra/newview/llpanelprofileclassifieds.cpp
+++ b/indra/newview/llpanelprofileclassifieds.cpp
@@ -77,7 +77,12 @@ class LLClassifiedHandler : public LLCommandHandler, public LLAvatarPropertiesOb
 public:
     // throttle calls from untrusted browsers
     LLClassifiedHandler() : LLCommandHandler("classified", UNTRUSTED_THROTTLE) {}
-	
+    ~LLClassifiedHandler()
+    {
+        if(LLAvatarPropertiesProcessor::instanceExists())
+            LLAvatarPropertiesProcessor::getInstance()->removeObserver(LLUUID(), this);
+    }
+
 	std::set<LLUUID> mClassifiedIds;
 	std::string mRequestVerb;
 
-- 
GitLab