diff --git a/Telegram/SourceFiles/ui/effects/animations.cpp b/Telegram/SourceFiles/ui/effects/animations.cpp index 1f1c83697..96d7fbbb1 100644 --- a/Telegram/SourceFiles/ui/effects/animations.cpp +++ b/Telegram/SourceFiles/ui/effects/animations.cpp @@ -118,17 +118,25 @@ void Manager::update() { } void Manager::updateQueued() { - InvokeQueued(this, [=] { update(); }); + Expects(_timerId == 0); + + _timerId = -1; + crl::on_main(delayedCallGuard(), [=] { + Expects(_timerId < 0); + + _timerId = 0; + update(); + }); } void Manager::schedule() { - if (_scheduled) { + if (_scheduled || _timerId < 0) { return; } stopTimer(); _scheduled = true; - Ui::PostponeCall(static_cast(this), [=] { + Ui::PostponeCall(delayedCallGuard(), [=] { _scheduled = false; if (_forceImmediateUpdate) { _forceImmediateUpdate = false; @@ -145,8 +153,12 @@ void Manager::schedule() { }); } +not_null Manager::delayedCallGuard() const { + return static_cast(this); +} + void Manager::stopTimer() { - if (_timerId) { + if (_timerId > 0) { killTimer(base::take(_timerId)); } } diff --git a/Telegram/SourceFiles/ui/effects/animations.h b/Telegram/SourceFiles/ui/effects/animations.h index 38c147a43..c5dee8b6d 100644 --- a/Telegram/SourceFiles/ui/effects/animations.h +++ b/Telegram/SourceFiles/ui/effects/animations.h @@ -158,6 +158,7 @@ private: void schedule(); void updateQueued(); void stopTimer(); + not_null delayedCallGuard() const; crl::time _lastUpdateTime = 0; int _timerId = 0;