From c9552390e76c53cf9b37dee634d4b4de095d2555 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 30 Apr 2019 12:56:21 +0400 Subject: [PATCH] Fix stack overflow crash in emoji panel hiding. A call to hideChildren before setting _hiding to the desired value could lead through leaveEvent to a recursive call to hideAnimated. --- .../SourceFiles/chat_helpers/tabbed_panel.cpp | 22 +++++++++++++------ .../SourceFiles/chat_helpers/tabbed_panel.h | 2 +- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp b/Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp index a8c56da20..c18992b5c 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp +++ b/Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp @@ -255,15 +255,21 @@ void TabbedPanel::hideByTimerOrLeave() { hideAnimated(); } -void TabbedPanel::prepareCache() { - if (_a_opacity.animating()) return; +void TabbedPanel::prepareCacheFor(bool hiding) { + if (_a_opacity.animating()) { + return; + } auto showAnimation = base::take(_a_show); auto showAnimationData = base::take(_showAnimation); + _hiding = false; showChildren(); + _cache = Ui::GrabWidget(this); - _showAnimation = base::take(showAnimationData); + _a_show = base::take(showAnimation); + _showAnimation = base::take(showAnimationData); + _hiding = hiding; if (_a_show.animating()) { hideChildren(); } @@ -273,11 +279,13 @@ void TabbedPanel::startOpacityAnimation(bool hiding) { if (_selector && !_selector->isHidden()) { _selector->beforeHiding(); } - _hiding = false; - prepareCache(); - _hiding = hiding; + prepareCacheFor(hiding); hideChildren(); - _a_opacity.start([this] { opacityAnimationCallback(); }, _hiding ? 1. : 0., _hiding ? 0. : 1., st::emojiPanDuration); + _a_opacity.start( + [=] { opacityAnimationCallback(); }, + _hiding ? 1. : 0., + _hiding ? 0. : 1., + st::emojiPanDuration); } void TabbedPanel::startShowAnimation() { diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_panel.h b/Telegram/SourceFiles/chat_helpers/tabbed_panel.h index 6f144a3a1..053eae7f4 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_panel.h +++ b/Telegram/SourceFiles/chat_helpers/tabbed_panel.h @@ -77,7 +77,7 @@ private: QImage grabForAnimation(); void startShowAnimation(); void startOpacityAnimation(bool hiding); - void prepareCache(); + void prepareCacheFor(bool hiding); void opacityAnimationCallback();