diff --git a/src/messages/MessageBuilder.cpp b/src/messages/MessageBuilder.cpp index 23d7c727b..7ea91fcfa 100644 --- a/src/messages/MessageBuilder.cpp +++ b/src/messages/MessageBuilder.cpp @@ -196,6 +196,11 @@ MessagePtr MessageBuilder::release() return ptr; } +std::weak_ptr MessageBuilder::weakOf() +{ + return this->message_; +} + void MessageBuilder::append(std::unique_ptr element) { this->message().elements.push_back(std::move(element)); diff --git a/src/messages/MessageBuilder.hpp b/src/messages/MessageBuilder.hpp index d3cbdb8d0..b09b82ed2 100644 --- a/src/messages/MessageBuilder.hpp +++ b/src/messages/MessageBuilder.hpp @@ -43,6 +43,7 @@ public: Message *operator->(); Message &message(); MessagePtr release(); + std::weak_ptr weakOf(); void append(std::unique_ptr element); QString matchLink(const QString &string); diff --git a/src/providers/LinkResolver.cpp b/src/providers/LinkResolver.cpp index 069dba691..679d9a5fe 100644 --- a/src/providers/LinkResolver.cpp +++ b/src/providers/LinkResolver.cpp @@ -15,6 +15,8 @@ void LinkResolver::getLinkInfo( QString requestUrl("https://braize.pajlada.com/chatterino/link_resolver/" + QUrl::toPercentEncoding(url, "", "/:")); + // Uncomment to test crashes + // QTimer::singleShot(3000, [=]() { NetworkRequest request(requestUrl); request.setCaller(QThread::currentThread()); request.setTimeout(30000); @@ -48,6 +50,7 @@ void LinkResolver::getLinkInfo( }); request.execute(); + // }); } } // namespace chatterino diff --git a/src/providers/twitch/TwitchMessageBuilder.cpp b/src/providers/twitch/TwitchMessageBuilder.cpp index e24cd6493..159e94b4a 100644 --- a/src/providers/twitch/TwitchMessageBuilder.cpp +++ b/src/providers/twitch/TwitchMessageBuilder.cpp @@ -544,8 +544,14 @@ void TwitchMessageBuilder::addTextOrEmoji(const QString &string_) ->setLink(link); LinkResolver::getLinkInfo( - linkString, [linkMELowercase, linkMEOriginal, linkString]( - QString tooltipText, Link originalLink) { + linkString, + [weakMessage = this->weakOf(), linkMELowercase, linkMEOriginal, + linkString](QString tooltipText, Link originalLink) { + auto shared = weakMessage.lock(); + if (!shared) + { + return; + } if (!tooltipText.isEmpty()) { linkMELowercase->setTooltip(tooltipText);