From 11e03a181d267447694c39e39df9c30ec5f9b52e Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 30 Sep 2020 21:05:19 +0300 Subject: [PATCH] Version 2.4: Fix crash in typing animations. --- Telegram/SourceFiles/data/data_session.cpp | 17 +++++++++++++++-- .../history/view/history_view_send_action.cpp | 5 +++++ .../history/view/history_view_send_action.h | 5 +++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index 25c62548b1..1a1e2865f8 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -880,7 +880,20 @@ HistoryView::SendActionPainter *Session::lookupSendActionPainter( return nullptr; } const auto j = i->second.find(rootId); - return (j == end(i->second)) ? nullptr : j->second.lock().get(); + if (j == end(i->second)) { + return nullptr; + } + const auto result = j->second.lock(); + if (!result) { + i->second.erase(j); + if (i->second.empty()) { + _sendActionPainters.erase(i); + } + return nullptr; + } + crl::on_main([copy = result] { + }); + return result.get(); } void Session::registerSendAction( @@ -959,7 +972,7 @@ bool Session::sendActionsAnimationCallback(crl::time now) { const auto sendAction = lookupSendActionPainter( i->first.first, i->first.second); - if (sendAction->updateNeedsAnimating(now)) { + if (sendAction && sendAction->updateNeedsAnimating(now)) { ++i; } else { i = _sendActions.erase(i); diff --git a/Telegram/SourceFiles/history/view/history_view_send_action.cpp b/Telegram/SourceFiles/history/view/history_view_send_action.cpp index c77a02156d..cd4ad548a8 100644 --- a/Telegram/SourceFiles/history/view/history_view_send_action.cpp +++ b/Telegram/SourceFiles/history/view/history_view_send_action.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_user.h" #include "data/data_session.h" +#include "main/main_session.h" #include "history/history.h" #include "lang/lang_keys.h" #include "ui/effects/animations.h" @@ -35,6 +36,7 @@ constexpr auto kStatusShowClientsidePlayGame = 10000; SendActionPainter::SendActionPainter(not_null history) : _history(history) +, _weak(&_history->session()) , _sendActionText(st::dialogsTextWidthMin) { } @@ -131,6 +133,9 @@ bool SendActionPainter::paint( } bool SendActionPainter::updateNeedsAnimating(crl::time now, bool force) { + if (!_weak) { + return false; + } auto changed = force; for (auto i = begin(_typing); i != end(_typing);) { if (now >= i->second) { diff --git a/Telegram/SourceFiles/history/view/history_view_send_action.h b/Telegram/SourceFiles/history/view/history_view_send_action.h index 8f4ebcddb2..2ad370eb9e 100644 --- a/Telegram/SourceFiles/history/view/history_view_send_action.h +++ b/Telegram/SourceFiles/history/view/history_view_send_action.h @@ -12,6 +12,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL class UserData; +namespace Main { +class Session; +} // namespace Main + namespace Api { enum class SendProgressType; struct SendProgress; @@ -42,6 +46,7 @@ public: private: const not_null _history; + const base::weak_ptr _weak; base::flat_map, crl::time> _typing; base::flat_map, Api::SendProgress> _sendActions; QString _sendActionString;