From 5afb2800c954adaf53fa94ad9f806880af784ae6 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sun, 5 Apr 2020 12:59:46 +0200 Subject: [PATCH] Make the "user info popup" crash less likely (hack v2) --- src/widgets/dialogs/UserInfoPopup.cpp | 38 ++++++++++++++++++++------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/src/widgets/dialogs/UserInfoPopup.cpp b/src/widgets/dialogs/UserInfoPopup.cpp index 7e2d3c7c..c399f8ef 100644 --- a/src/widgets/dialogs/UserInfoPopup.cpp +++ b/src/widgets/dialogs/UserInfoPopup.cpp @@ -379,7 +379,12 @@ void UserInfoPopup::updateUserData() { std::weak_ptr hack = this->hack_; - const auto onUserFetchFailed = [this] { + const auto onUserFetchFailed = [this, hack] { + if (!hack.lock()) + { + return; + } + // this can occur when the account doesn't exist. this->ui_.followerCountLabel->setText( TEXT_FOLLOWERS.arg(TEXT_UNAVAILABLE)); @@ -394,6 +399,11 @@ void UserInfoPopup::updateUserData() QString(TEXT_UNAVAILABLE)); }; const auto onUserFetched = [this, hack](const auto &user) { + if (!hack.lock()) + { + return; + } + auto currentUser = getApp()->accounts->twitch.getCurrent(); this->userId_ = user.id; @@ -404,7 +414,11 @@ void UserInfoPopup::updateUserData() this->ui_.viewCountLabel->setText(TEXT_VIEWS.arg(user.viewCount)); getKraken()->getUser( user.id, - [this](const auto &user) { + [this, hack](const auto &user) { + if (!hack.lock()) + { + return; + } this->ui_.createdDateLabel->setText( TEXT_CREATED.arg(user.createdAt.section("T", 0, 0))); }, @@ -415,7 +429,11 @@ void UserInfoPopup::updateUserData() getHelix()->getUserFollowers( user.id, - [this](const auto &followers) { + [this, hack](const auto &followers) { + if (!hack.lock()) + { + return; + } this->ui_.followerCountLabel->setText( TEXT_FOLLOWERS.arg(followers.total)); }, @@ -425,14 +443,14 @@ void UserInfoPopup::updateUserData() // get follow state currentUser->checkFollow(user.id, [this, hack](auto result) { - if (hack.lock()) + if (!hack.lock()) { - if (result != FollowResult_Failed) - { - this->ui_.follow->setEnabled(true); - this->ui_.follow->setChecked(result == - FollowResult_Following); - } + return; + } + if (result != FollowResult_Failed) + { + this->ui_.follow->setEnabled(true); + this->ui_.follow->setChecked(result == FollowResult_Following); } });