From d34eabdc111c9d8c1440c5b4dfe19884e854507e Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 24 Aug 2020 17:59:44 +0400 Subject: [PATCH] Fix crash in poll view destruction. --- .../history/view/media/history_view_media.h | 4 ++-- .../history/view/media/history_view_poll.cpp | 18 +++++++++++++++++- .../view/media/history_view_sticker.cpp | 6 ++++-- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/Telegram/SourceFiles/history/view/media/history_view_media.h b/Telegram/SourceFiles/history/view/media/history_view_media.h index cb74586122..76ac7bc26a 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_media.h +++ b/Telegram/SourceFiles/history/view/media/history_view_media.h @@ -55,7 +55,7 @@ enum class MediaInBubbleState { class Media : public Object { public: - Media(not_null parent) : _parent(parent) { + explicit Media(not_null parent) : _parent(parent) { } [[nodiscard]] not_null history() const; @@ -284,7 +284,7 @@ protected: virtual void playAnimation(bool autoplay) { } - not_null _parent; + const not_null _parent; MediaInBubbleState _inBubbleState = MediaInBubbleState::None; }; diff --git a/Telegram/SourceFiles/history/view/media/history_view_poll.cpp b/Telegram/SourceFiles/history/view/media/history_view_poll.cpp index 0969a95c5a..2df30b38f1 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_poll.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_poll.cpp @@ -485,11 +485,27 @@ void Poll::updateRecentVoters() { ranges::equal_to(), &RecentVoter::user); if (changed) { - _recentVoters = ranges::view::all( + auto updated = ranges::view::all( sliced ) | ranges::views::transform([](not_null user) { return RecentVoter{ user }; }) | ranges::to_vector; + const auto has = hasHeavyPart(); + if (has) { + for (auto &voter : updated) { + const auto i = ranges::find( + _recentVoters, + voter.user, + &RecentVoter::user); + if (i != end(_recentVoters)) { + voter.userpic = std::move(i->userpic); + } + } + } + _recentVoters = std::move(updated); + if (has && !hasHeavyPart()) { + _parent->checkHeavyPart(); + } } } diff --git a/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp b/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp index 5cc8338357..7101a1f2bd 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp @@ -80,11 +80,13 @@ Sticker::Sticker( Sticker::~Sticker() { if (_lottie || _dataMedia) { - unloadLottie(); + if (_lottie) { + unloadLottie(); + } if (_dataMedia) { _data->owner().keepAlive(base::take(_dataMedia)); + _parent->checkHeavyPart(); } - _parent->checkHeavyPart(); } }