diff options
author | Rye Mutt <rye@alchemyviewer.org> | 2022-10-19 16:28:34 -0400 |
---|---|---|
committer | Rye Mutt <rye@alchemyviewer.org> | 2022-10-19 16:28:34 -0400 |
commit | 5456af4c8ce8c2bef7d544cd8a928ea399832756 (patch) | |
tree | c510874defae368bce1edd6b4c7c1ae0e0bf4587 | |
parent | bbd8df15de6b8f9b321f251c3e764ea654d5ecc7 (diff) |
Fix various menu leaks and lazy creation in chiclets, bump floater, media controls, and the mini map
-rw-r--r-- | indra/newview/llchiclet.cpp | 66 | ||||
-rw-r--r-- | indra/newview/llchiclet.h | 6 | ||||
-rw-r--r-- | indra/newview/llfloaterbump.cpp | 35 | ||||
-rw-r--r-- | indra/newview/llfloaterbump.h | 2 | ||||
-rw-r--r-- | indra/newview/llmediactrl.cpp | 50 | ||||
-rw-r--r-- | indra/newview/llmediactrl.h | 4 | ||||
-rw-r--r-- | indra/newview/llnetmap.cpp | 28 | ||||
-rw-r--r-- | indra/newview/llnetmap.h | 2 |
8 files changed, 126 insertions, 67 deletions
diff --git a/indra/newview/llchiclet.cpp b/indra/newview/llchiclet.cpp index 0f187b0ecf..cc4f4536a4 100644 --- a/indra/newview/llchiclet.cpp +++ b/indra/newview/llchiclet.cpp @@ -67,7 +67,6 @@ LLSysWellChiclet::LLSysWellChiclet(const Params& p) , mMaxDisplayedCount(p.max_displayed_count) , mIsNewMessagesState(false) , mFlashToLitTimer(NULL) - , mContextMenu(NULL) { LLButton::Params button_params = p.button; mButton = LLUICtrlFactory::create<LLButton>(button_params); @@ -79,6 +78,12 @@ LLSysWellChiclet::LLSysWellChiclet(const Params& p) LLSysWellChiclet::~LLSysWellChiclet() { mFlashToLitTimer->unset(); + LLContextMenu* menu = static_cast<LLContextMenu*>(mContextMenuHandle.get()); + if (menu) + { + menu->die(); + mContextMenuHandle.markDead(); + } } void LLSysWellChiclet::setCounter(S32 counter) @@ -145,14 +150,16 @@ void LLSysWellChiclet::updateWidget(bool is_window_empty) // virtual BOOL LLSysWellChiclet::handleRightMouseDown(S32 x, S32 y, MASK mask) { - if(!mContextMenu) + LLContextMenu* menu_avatar = mContextMenuHandle.get(); + if(!menu_avatar) { createMenu(); + menu_avatar = mContextMenuHandle.get(); } - if (mContextMenu) + if (menu_avatar) { - mContextMenu->show(x, y); - LLMenuGL::showPopup(this, mContextMenu, x, y); + menu_avatar->show(x, y); + LLMenuGL::showPopup(this, menu_avatar, x, y); } return TRUE; } @@ -192,7 +199,7 @@ bool LLNotificationChiclet::enableMenuItem(const LLSD& user_data) void LLNotificationChiclet::createMenu() { - if(mContextMenu) + if(mContextMenuHandle.get()) { LL_WARNS() << "Menu already exists" << LL_ENDL; return; @@ -207,10 +214,14 @@ void LLNotificationChiclet::createMenu() boost::bind(&LLNotificationChiclet::enableMenuItem, this, _2)); llassert(LLMenuGL::sMenuContainer != NULL); - mContextMenu = LLUICtrlFactory::getInstance()->createFromFile<LLContextMenu> + LLContextMenu* menu = LLUICtrlFactory::getInstance()->createFromFile<LLContextMenu> ("menu_notification_well_button.xml", LLMenuGL::sMenuContainer, LLViewerMenuHolderGL::child_registry_t::instance()); + if (menu) + { + mContextMenuHandle = menu->getHandle(); + } } /*virtual*/ @@ -309,10 +320,19 @@ LLIMChiclet::LLIMChiclet(const LLIMChiclet::Params& p) , mDefaultWidth(p.rect().getWidth()) , mNewMessagesIcon(NULL) , mChicletButton(NULL) -, mPopupMenu(NULL) { } +LLIMChiclet::~LLIMChiclet() +{ + auto menu = mPopupMenuHandle.get(); + if (menu) + { + menu->die(); + mPopupMenuHandle.markDead(); + } +} + /* virtual*/ BOOL LLIMChiclet::postBuild() { @@ -364,16 +384,18 @@ void LLIMChiclet::setToggleState(bool toggle) BOOL LLIMChiclet::handleRightMouseDown(S32 x, S32 y, MASK mask) { - if(!mPopupMenu) + auto menu = static_cast<LLMenuGL*>(mPopupMenuHandle.get()); + if(!menu) { createPopupMenu(); + menu = static_cast<LLMenuGL*>(mPopupMenuHandle.get()); } - if (mPopupMenu) + if (menu) { updateMenuItems(); - mPopupMenu->arrangeAndClear(); - LLMenuGL::showPopup(this, mPopupMenu, x, y); + menu->arrangeAndClear(); + LLMenuGL::showPopup(this, menu, x, y); } return TRUE; @@ -381,15 +403,16 @@ BOOL LLIMChiclet::handleRightMouseDown(S32 x, S32 y, MASK mask) void LLIMChiclet::hidePopupMenu() { - if (mPopupMenu) + auto menu = mPopupMenuHandle.get(); + if (menu) { - mPopupMenu->setVisible(FALSE); + menu->setVisible(FALSE); } } bool LLIMChiclet::canCreateMenu() { - if(mPopupMenu) + if(mPopupMenuHandle.get()) { LL_WARNS() << "Menu already exists" << LL_ENDL; return false; @@ -1107,8 +1130,13 @@ void LLScriptChiclet::createPopupMenu() LLUICtrl::CommitCallbackRegistry::ScopedRegistrar registrar; registrar.add("ScriptChiclet.Action", boost::bind(&LLScriptChiclet::onMenuItemClicked, this, _2)); - mPopupMenu = LLUICtrlFactory::getInstance()->createFromFile<LLMenuGL> + LLMenuGL* menu = LLUICtrlFactory::getInstance()->createFromFile<LLMenuGL> ("menu_script_chiclet.xml", gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance()); + if (menu) + { + mPopupMenuHandle = menu->getHandle(); + } + } ////////////////////////////////////////////////////////////////////////// @@ -1185,8 +1213,12 @@ void LLInvOfferChiclet::createPopupMenu() LLUICtrl::CommitCallbackRegistry::ScopedRegistrar registrar; registrar.add("InvOfferChiclet.Action", boost::bind(&LLInvOfferChiclet::onMenuItemClicked, this, _2)); - mPopupMenu = LLUICtrlFactory::getInstance()->createFromFile<LLMenuGL> + LLMenuGL* menu = LLUICtrlFactory::getInstance()->createFromFile<LLMenuGL> ("menu_inv_offer_chiclet.xml", gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance()); + if (menu) + { + mPopupMenuHandle = menu->getHandle(); + } } // EOF diff --git a/indra/newview/llchiclet.h b/indra/newview/llchiclet.h index aceedda07e..58a797218f 100644 --- a/indra/newview/llchiclet.h +++ b/indra/newview/llchiclet.h @@ -252,7 +252,7 @@ public: {}; - virtual ~LLIMChiclet() {}; + virtual ~LLIMChiclet(); /** * It is used for default setting up of chicklet:click handler, etc. @@ -325,7 +325,7 @@ protected: bool canCreateMenu(); - LLMenuGL* mPopupMenu; + LLHandle<LLUICtrl> mPopupMenuHandle; bool mShowSpeaker; bool mCounterEnabled; @@ -519,7 +519,7 @@ protected: bool mIsNewMessagesState; LLFlashTimer* mFlashToLitTimer; - LLContextMenu* mContextMenu; + LLHandle<LLContextMenu> mContextMenuHandle; }; class LLNotificationChiclet : public LLSysWellChiclet diff --git a/indra/newview/llfloaterbump.cpp b/indra/newview/llfloaterbump.cpp index 33e4c7cd5f..307ab8c4d1 100644 --- a/indra/newview/llfloaterbump.cpp +++ b/indra/newview/llfloaterbump.cpp @@ -69,6 +69,12 @@ LLFloaterBump::LLFloaterBump(const LLSD& key) // Destroys the object LLFloaterBump::~LLFloaterBump() { + auto menu = mPopupMenuHandle.get(); + if (menu) + { + menu->die(); + mPopupMenuHandle.markDead(); + } } BOOL LLFloaterBump::postBuild() @@ -77,11 +83,15 @@ BOOL LLFloaterBump::postBuild() mList->setAllowMultipleSelection(false); mList->setRightMouseDownCallback(boost::bind(&LLFloaterBump::onScrollListRightClicked, this, _1, _2, _3)); - mPopupMenu = LLUICtrlFactory::getInstance()->createFromFile<LLContextMenu>("menu_avatar_other.xml", gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance()); - mPopupMenu->setItemVisible(std::string("Normal"), false); - mPopupMenu->setItemVisible(std::string("Always use impostor"), false); - mPopupMenu->setItemVisible(std::string("Never use impostor"), false); - mPopupMenu->setItemVisible(std::string("Impostor seperator"), false); + LLContextMenu* menu = LLUICtrlFactory::getInstance()->createFromFile<LLContextMenu>("menu_avatar_other.xml", gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance()); + if (menu) + { + mPopupMenuHandle = menu->getHandle(); + menu->setItemVisible(std::string("Normal"), false); + menu->setItemVisible(std::string("Always use impostor"), false); + menu->setItemVisible(std::string("Never use impostor"), false); + menu->setItemVisible(std::string("Impostor seperator"), false); + } return TRUE; } @@ -176,18 +186,19 @@ void LLFloaterBump::onScrollListRightClicked(LLUICtrl* ctrl, S32 x, S32 y) if (!gMeanCollisionList.empty()) { LLScrollListItem* item = mList->hitItem(x, y); - if (item && mPopupMenu) + auto menu = mPopupMenuHandle.get(); + if (item && menu) { mItemUUID = item->getUUID(); - mPopupMenu->buildDrawLabels(); - mPopupMenu->updateParent(LLMenuGL::sMenuContainer); + menu->buildDrawLabels(); + menu->updateParent(LLMenuGL::sMenuContainer); std::string mute_msg = (LLMuteList::getInstance()->isMuted(mItemUUID, mNames[mItemUUID])) ? "UnmuteAvatar" : "MuteAvatar"; - mPopupMenu->getChild<LLUICtrl>("Avatar Mute")->setValue(LLTrans::getString(mute_msg)); - mPopupMenu->setItemEnabled(std::string("Zoom In"), bool(gObjectList.findObject(mItemUUID))); + menu->getChild<LLUICtrl>("Avatar Mute")->setValue(LLTrans::getString(mute_msg)); + menu->setItemEnabled(std::string("Zoom In"), bool(gObjectList.findObject(mItemUUID))); - ((LLContextMenu*)mPopupMenu)->show(x, y); - LLMenuGL::showPopup(ctrl, mPopupMenu, x, y); + menu->show(x, y); + LLMenuGL::showPopup(ctrl, menu, x, y); } } } diff --git a/indra/newview/llfloaterbump.h b/indra/newview/llfloaterbump.h index ce52c75255..d2f9fabdd3 100644 --- a/indra/newview/llfloaterbump.h +++ b/indra/newview/llfloaterbump.h @@ -68,7 +68,7 @@ private: virtual ~LLFloaterBump(); LLScrollListCtrl* mList; - LLMenuGL* mPopupMenu; + LLHandle<LLContextMenu> mPopupMenuHandle; LLUUID mItemUUID; typedef std::map<LLUUID, std::string> uuid_map_t; diff --git a/indra/newview/llmediactrl.cpp b/indra/newview/llmediactrl.cpp index 9142aadab9..36ac1bdf97 100644 --- a/indra/newview/llmediactrl.cpp +++ b/indra/newview/llmediactrl.cpp @@ -106,7 +106,6 @@ LLMediaCtrl::LLMediaCtrl( const Params& p) : mTrusted(p.trusted_content), mWindowShade(NULL), mHoverTextChanged(false), - mContextMenu(NULL), mAllowFileDownload(false) { { @@ -151,6 +150,13 @@ LLMediaCtrl::LLMediaCtrl( const Params& p) : LLMediaCtrl::~LLMediaCtrl() { + auto menu = mContextMenuHandle.get(); + if (menu) + { + menu->die(); + mContextMenuHandle.markDead(); + } + if (mMediaSource) { mMediaSource->remObserver( this ); @@ -336,15 +342,33 @@ BOOL LLMediaCtrl::handleRightMouseDown( S32 x, S32 y, MASK mask ) setFocus( TRUE ); } - if (mContextMenu) + auto menu = mContextMenuHandle.get(); + if (!menu) + { + LLUICtrl::CommitCallbackRegistry::ScopedRegistrar registar; + registar.add("Open.WebInspector", boost::bind(&LLMediaCtrl::onOpenWebInspector, this)); + + // stinson 05/05/2014 : use this as the parent of the context menu if the static menu + // container has yet to be created + LLPanel* menuParent = (LLMenuGL::sMenuContainer != NULL) ? dynamic_cast<LLPanel*>(LLMenuGL::sMenuContainer) : dynamic_cast<LLPanel*>(this); + llassert(menuParent != NULL); + menu = LLUICtrlFactory::getInstance()->createFromFile<LLContextMenu>( + "menu_media_ctrl.xml", menuParent, LLViewerMenuHolderGL::child_registry_t::instance()); + if (menu) + { + mContextMenuHandle = menu->getHandle(); + } + } + + if (menu) { // hide/show debugging options bool media_plugin_debugging_enabled = gSavedSettings.getBOOL("MediaPluginDebugging"); - mContextMenu->setItemVisible("open_webinspector", media_plugin_debugging_enabled ); - mContextMenu->setItemVisible("debug_separator", media_plugin_debugging_enabled ); + menu->setItemVisible("open_webinspector", media_plugin_debugging_enabled ); + menu->setItemVisible("debug_separator", media_plugin_debugging_enabled ); - mContextMenu->show(x, y); - LLMenuGL::showPopup(this, mContextMenu, x, y); + menu->show(x, y); + LLMenuGL::showPopup(this, menu, x, y); } return TRUE; @@ -409,15 +433,6 @@ void LLMediaCtrl::onFocusLost() // BOOL LLMediaCtrl::postBuild () { - LLUICtrl::CommitCallbackRegistry::ScopedRegistrar registar; - registar.add("Open.WebInspector", boost::bind(&LLMediaCtrl::onOpenWebInspector, this)); - - // stinson 05/05/2014 : use this as the parent of the context menu if the static menu - // container has yet to be created - LLPanel* menuParent = (LLMenuGL::sMenuContainer != NULL) ? dynamic_cast<LLPanel*>(LLMenuGL::sMenuContainer) : dynamic_cast<LLPanel*>(this); - llassert(menuParent != NULL); - mContextMenu = LLUICtrlFactory::getInstance()->createFromFile<LLContextMenu>( - "menu_media_ctrl.xml", menuParent, LLViewerMenuHolderGL::child_registry_t::instance()); setVisibleCallback(boost::bind(&LLMediaCtrl::onVisibilityChanged, this, _2)); return TRUE; @@ -1230,11 +1245,6 @@ void LLMediaCtrl::setTrustedContent(bool trusted) } } -void LLMediaCtrl::updateContextMenuParent(LLView* pNewParent) -{ - mContextMenu->updateParent(pNewParent); -} - bool LLMediaCtrl::wantsKeyUpKeyDown() const { return true; diff --git a/indra/newview/llmediactrl.h b/indra/newview/llmediactrl.h index bc4cbaae68..487c654adc 100644 --- a/indra/newview/llmediactrl.h +++ b/indra/newview/llmediactrl.h @@ -174,8 +174,6 @@ public: LLUUID getTextureID() {return mMediaTextureID;} - void updateContextMenuParent(LLView* pNewParent); - // The Browser windows want keyup and keydown events. Overridden from LLFocusableElement to return true. virtual bool wantsKeyUpKeyDown() const; virtual bool wantsReturnKey() const; @@ -220,7 +218,7 @@ public: mTextureHeight; class LLWindowShade* mWindowShade; - LLContextMenu* mContextMenu; + LLHandle<LLContextMenu> mContextMenuHandle; }; #endif // LL_LLMediaCtrl_H diff --git a/indra/newview/llnetmap.cpp b/indra/newview/llnetmap.cpp index 1240ce7c0f..245fec30c9 100644 --- a/indra/newview/llnetmap.cpp +++ b/indra/newview/llnetmap.cpp @@ -93,8 +93,7 @@ LLNetMap::LLNetMap (const Params & p) mObjectImagep(), mClosestAgentToCursor(), mClosestAgentAtLastRightClick(), - mToolTipMsg(), - mPopupMenu(NULL) + mToolTipMsg() { mScale = gSavedSettings.getF32("MiniMapScale"); mPixelsPerMeter = mScale / REGION_WIDTH_METERS; @@ -103,6 +102,12 @@ LLNetMap::LLNetMap (const Params & p) LLNetMap::~LLNetMap() { + auto menu = static_cast<LLMenuGL*>(mPopupMenuHandle.get()); + if (menu) + { + menu->die(); + mPopupMenuHandle.markDead(); + } } BOOL LLNetMap::postBuild() @@ -112,7 +117,8 @@ BOOL LLNetMap::postBuild() registrar.add("Minimap.Zoom", boost::bind(&LLNetMap::handleZoom, this, _2)); registrar.add("Minimap.Tracker", boost::bind(&LLNetMap::handleStopTracking, this, _2)); - mPopupMenu = LLUICtrlFactory::getInstance()->createFromFile<LLMenuGL>("menu_mini_map.xml", gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance()); + LLMenuGL* menu = LLUICtrlFactory::getInstance()->createFromFile<LLMenuGL>("menu_mini_map.xml", gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance()); + mPopupMenuHandle = menu->getHandle(); return TRUE; } @@ -859,12 +865,13 @@ BOOL LLNetMap::handleMouseUp( S32 x, S32 y, MASK mask ) BOOL LLNetMap::handleRightMouseDown(S32 x, S32 y, MASK mask) { - if (mPopupMenu) + auto menu = static_cast<LLMenuGL*>(mPopupMenuHandle.get()); + if (menu) { - mPopupMenu->buildDrawLabels(); - mPopupMenu->updateParent(LLMenuGL::sMenuContainer); - mPopupMenu->setItemEnabled("Stop Tracking", LLTracker::isTracking(0)); - LLMenuGL::showPopup(this, mPopupMenu, x, y); + menu->buildDrawLabels(); + menu->updateParent(LLMenuGL::sMenuContainer); + menu->setItemEnabled("Stop Tracking", LLTracker::isTracking(0)); + LLMenuGL::showPopup(this, menu, x, y); } return TRUE; } @@ -990,9 +997,10 @@ void LLNetMap::handleZoom(const LLSD& userdata) void LLNetMap::handleStopTracking (const LLSD& userdata) { - if (mPopupMenu) + auto menu = static_cast<LLMenuGL*>(mPopupMenuHandle.get()); + if (menu) { - mPopupMenu->setItemEnabled ("Stop Tracking", false); + menu->setItemEnabled ("Stop Tracking", false); LLTracker::stopTracking (LLTracker::isTracking(NULL)); } } diff --git a/indra/newview/llnetmap.h b/indra/newview/llnetmap.h index 1f7e7d68c6..0adb78d2c8 100644 --- a/indra/newview/llnetmap.h +++ b/indra/newview/llnetmap.h @@ -134,7 +134,7 @@ private: void handleZoom(const LLSD& userdata); void handleStopTracking (const LLSD& userdata); - LLMenuGL* mPopupMenu; + LLHandle<LLView> mPopupMenuHandle; uuid_vec_t gmSelected; }; |