From cdf85c50840825ed64bfae97fb4a25b8b11c6860 Mon Sep 17 00:00:00 2001 From: pajlada Date: Sun, 5 Jul 2020 07:52:24 -0400 Subject: [PATCH] Message menu now holds a shared pointer to a layout (#1787) This ensures that the layout will survive for the lifetime of the menu, so any of the menu actions can with confidence do things with the layout, not having to worry whether it's dead or not. This means that the user, while having the message menu open, could have one extra MessageLayout alive. I have ensured that when the menu dies the reference to the shared pointer dies with it. --- CHANGELOG.md | 1 + src/widgets/helper/ChannelView.cpp | 16 +++++++++------- src/widgets/helper/ChannelView.hpp | 4 ++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e81e8763..8235bb3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,5 +9,6 @@ - Bugfix: Fix preview on hover not working when Animated emotes options was disabled (#1546) - Bugfix: FFZ custom mod badges no longer scale with the emote scale options (#1602) - Bugfix: MacOS updater looked for non-existing fields, causing it to always fail the update check (#1642) +- Bugfix: Fixed message menu crashing if the message you right-clicked goes out of scope before you select an action (#1783) (#1787) - Settings open faster - Dev: Fully remove Twitch Chatroom support diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index afc5d370..25c9db43 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -1570,12 +1570,12 @@ void ChannelView::mouseReleaseEvent(QMouseEvent *event) } // handle the click - this->handleMouseClick(event, hoverLayoutElement, layout.get()); + this->handleMouseClick(event, hoverLayoutElement, layout); } void ChannelView::handleMouseClick(QMouseEvent *event, const MessageLayoutElement *hoveredElement, - MessageLayout *layout) + MessageLayoutPtr layout) { switch (event->button()) { @@ -1593,7 +1593,7 @@ void ChannelView::handleMouseClick(QMouseEvent *event, auto &link = hoveredElement->getLink(); if (!getSettings()->linksDoubleClickOnly) { - this->handleLinkClick(event, link, layout); + this->handleLinkClick(event, link, layout.get()); } // Invoke to signal from EmotePopup. @@ -1631,7 +1631,7 @@ void ChannelView::handleMouseClick(QMouseEvent *event, auto &link = hoveredElement->getLink(); if (!getSettings()->linksDoubleClickOnly) { - this->handleLinkClick(event, link, layout); + this->handleLinkClick(event, link, layout.get()); } } break; @@ -1640,13 +1640,15 @@ void ChannelView::handleMouseClick(QMouseEvent *event, } void ChannelView::addContextMenuItems( - const MessageLayoutElement *hoveredElement, MessageLayout *layout) + const MessageLayoutElement *hoveredElement, MessageLayoutPtr layout) { const auto &creator = hoveredElement->getCreator(); auto creatorFlags = creator.getFlags(); - static QMenu *menu = new QMenu; - menu->clear(); + auto menu = new QMenu; + connect(menu, &QMenu::aboutToHide, [menu] { + menu->deleteLater(); // + }); // Emote actions if (creatorFlags.hasAny( diff --git a/src/widgets/helper/ChannelView.hpp b/src/widgets/helper/ChannelView.hpp index 6700ea67..1e4d764b 100644 --- a/src/widgets/helper/ChannelView.hpp +++ b/src/widgets/helper/ChannelView.hpp @@ -145,9 +145,9 @@ private: void handleMouseClick(QMouseEvent *event, const MessageLayoutElement *hoverLayoutElement, - MessageLayout *layout); + MessageLayoutPtr layout); void addContextMenuItems(const MessageLayoutElement *hoveredElement, - MessageLayout *layout); + MessageLayoutPtr layout); int getLayoutWidth() const; void updatePauses(); void unpaused();