From 65a14fb95be97afdba6937048f6522dfd056c77e Mon Sep 17 00:00:00 2001 From: nerix Date: Sat, 10 Jun 2023 13:40:30 +0200 Subject: [PATCH] Fix crash resulting from a mutex deadlock when switching users (#4675) --- CHANGELOG.md | 1 + src/widgets/dialogs/ReplyThreadPopup.cpp | 35 ++++++++++++------------ src/widgets/dialogs/ReplyThreadPopup.hpp | 2 ++ 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 285c736a..fc94beb1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Minor: Added `/shoutout ` commands to shoutout specified user. (#4638) - Minor: Improved editing hotkeys. (#4628) - Bugfix: Fixed generation of crashdumps by the browser-extension process when the browser was closed. (#4667) +- Bugfix: Fixed a crash when opening and closing a reply thread and switching the user. (#4675) - Dev: Added command to set Qt's logging filter/rules at runtime (`/c2-set-logging-rules`). (#4637) - Dev: Added the ability to see & load custom themes from the Themes directory. No stable promises are made of this feature, changes might be made that breaks custom themes without notice. (#4570) - Dev: Added test cases for emote and tab completion. (#4644) diff --git a/src/widgets/dialogs/ReplyThreadPopup.cpp b/src/widgets/dialogs/ReplyThreadPopup.cpp index fc92da91..1a1c9871 100644 --- a/src/widgets/dialogs/ReplyThreadPopup.cpp +++ b/src/widgets/dialogs/ReplyThreadPopup.cpp @@ -138,26 +138,25 @@ void ReplyThreadPopup::addMessagesFromThread() this->setWindowTitle(TEXT_TITLE.arg(this->thread_->root()->loginName, sourceChannel->getName())); - ChannelPtr virtualChannel; if (sourceChannel->isTwitchChannel()) { - virtualChannel = + this->virtualChannel_ = std::make_shared(sourceChannel->getName()); } else { - virtualChannel = std::make_shared(sourceChannel->getName(), - Channel::Type::None); + this->virtualChannel_ = std::make_shared( + sourceChannel->getName(), Channel::Type::None); } - this->ui_.threadView->setChannel(virtualChannel); + this->ui_.threadView->setChannel(this->virtualChannel_); this->ui_.threadView->setSourceChannel(sourceChannel); auto overrideFlags = boost::optional(this->thread_->root()->flags); overrideFlags->set(MessageFlag::DoNotLog); - virtualChannel->addMessage(this->thread_->root(), overrideFlags); + this->virtualChannel_->addMessage(this->thread_->root(), overrideFlags); for (const auto &msgRef : this->thread_->replies()) { if (auto msg = msgRef.lock()) @@ -165,24 +164,24 @@ void ReplyThreadPopup::addMessagesFromThread() auto overrideFlags = boost::optional(msg->flags); overrideFlags->set(MessageFlag::DoNotLog); - virtualChannel->addMessage(msg, overrideFlags); + this->virtualChannel_->addMessage(msg, overrideFlags); } } this->messageConnection_ = std::make_unique( - sourceChannel->messageAppended.connect( - [this, virtualChannel](MessagePtr &message, auto) { - if (message->replyThread == this->thread_) - { - auto overrideFlags = - boost::optional(message->flags); - overrideFlags->set(MessageFlag::DoNotLog); + sourceChannel->messageAppended.connect([this](MessagePtr &message, + auto) { + if (message->replyThread == this->thread_) + { + auto overrideFlags = + boost::optional(message->flags); + overrideFlags->set(MessageFlag::DoNotLog); - // same reply thread, add message - virtualChannel->addMessage(message, overrideFlags); - } - })); + // same reply thread, add message + this->virtualChannel_->addMessage(message, overrideFlags); + } + })); } void ReplyThreadPopup::updateInputUI() diff --git a/src/widgets/dialogs/ReplyThreadPopup.hpp b/src/widgets/dialogs/ReplyThreadPopup.hpp index 863274e5..613cf4ee 100644 --- a/src/widgets/dialogs/ReplyThreadPopup.hpp +++ b/src/widgets/dialogs/ReplyThreadPopup.hpp @@ -34,6 +34,8 @@ private: std::shared_ptr thread_; // The channel that the reply thread is in ChannelPtr channel_; + // The channel for the `threadView` + ChannelPtr virtualChannel_; Split *split_; struct {