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.
This commit is contained in:
pajlada 2020-07-05 07:52:24 -04:00 committed by GitHub
parent e4af009fda
commit cdf85c5084
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 9 deletions

View file

@ -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

View file

@ -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(

View file

@ -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();