From 2a4dea528f670b9bb1f77ef27a8a1dd16603d114 Mon Sep 17 00:00:00 2001 From: Jacek Antonelli Date: Fri, 15 Aug 2008 23:45:50 -0500 Subject: Second Life viewer sources 1.20.7 --- linden/indra/newview/llfloaterproperties.cpp | 35 +++++++++++++++++++++------- 1 file changed, 27 insertions(+), 8 deletions(-) (limited to 'linden/indra/newview/llfloaterproperties.cpp') diff --git a/linden/indra/newview/llfloaterproperties.cpp b/linden/indra/newview/llfloaterproperties.cpp index 0d2cd5f..48232cb 100644 --- a/linden/indra/newview/llfloaterproperties.cpp +++ b/linden/indra/newview/llfloaterproperties.cpp @@ -65,11 +65,21 @@ // helper class to watch the inventory. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -class LLPropertiesObserver : public LLInventoryObserver, public LLSingleton +// Ugh. This can't be a singleton because it needs to remove itself +// from the inventory observer list when destroyed, which could +// happen after gInventory has already been destroyed if a singleton. +// Instead, do our own ref counting and create / destroy it as needed +class LLPropertiesObserver : public LLInventoryObserver { public: - LLPropertiesObserver() {} - virtual ~LLPropertiesObserver() {} + LLPropertiesObserver() + { + gInventory.addObserver(this); + } + virtual ~LLPropertiesObserver() + { + gInventory.removeObserver(this); + } virtual void changed(U32 mask); }; @@ -88,7 +98,10 @@ void LLPropertiesObserver::changed(U32 mask) /// Class LLFloaterProperties ///---------------------------------------------------------------------------- +// static LLFloaterProperties::instance_map LLFloaterProperties::sInstances; +LLPropertiesObserver* LLFloaterProperties::sPropertiesObserver = NULL; +S32 LLFloaterProperties::sPropertiesObserverCount = 0; // static LLFloaterProperties* LLFloaterProperties::find(const LLUUID& item_id, @@ -145,12 +158,12 @@ LLFloaterProperties::LLFloaterProperties(const std::string& name, const LLRect& { LLUICtrlFactory::getInstance()->buildFloater(this,"floater_inventory_item_properties.xml"); - // hack to make sure these floaters are observing the inventory. - if(!gInventory.containsObserver(LLPropertiesObserver::getInstance())) + if (!sPropertiesObserver) { - // Note: this is where gPropertiesObserver used to be constructed. - gInventory.addObserver(LLPropertiesObserver::getInstance()); + sPropertiesObserver = new LLPropertiesObserver; } + sPropertiesObserverCount++; + // add the object to the static structure LLUUID key = mItemID ^ mObjectID; sInstances.insert(instance_map::value_type(key, this)); @@ -193,6 +206,12 @@ LLFloaterProperties::~LLFloaterProperties() { sInstances.erase(it); } + sPropertiesObserverCount--; + if (!sPropertiesObserverCount) + { + delete sPropertiesObserver; + sPropertiesObserver = NULL; + } } void LLFloaterProperties::refresh() @@ -422,7 +441,7 @@ void LLFloaterProperties::refreshFromItem(LLInventoryItem* item) perm_string = "G"; perm_string += overwrite_group ? "*: " : ": "; - perm_string += perm_string += mask_to_string(group_mask); + perm_string += mask_to_string(group_mask); childSetText("GroupMaskDebug",perm_string); childSetVisible("GroupMaskDebug",TRUE); -- cgit v1.1