From dffe79fea81b4fde61ba64795fa51878eeeb04bb Mon Sep 17 00:00:00 2001 From: John Preston Date: Sat, 22 Apr 2023 21:20:10 +0400 Subject: [PATCH] Fix possible crash in nested section show. --- Telegram/SourceFiles/info/info_wrap_widget.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Telegram/SourceFiles/info/info_wrap_widget.cpp b/Telegram/SourceFiles/info/info_wrap_widget.cpp index 2d53f03162..0c5ba45ed9 100644 --- a/Telegram/SourceFiles/info/info_wrap_widget.cpp +++ b/Telegram/SourceFiles/info/info_wrap_widget.cpp @@ -759,9 +759,9 @@ bool WrapWidget::returnToFirstStackFrame( void WrapWidget::showNewContent( not_null memento, const Window::SectionShow ¶ms) { - auto saveToStack = (_content != nullptr) + const auto saveToStack = (_content != nullptr) && (params.way == Window::SectionShow::Way::Forward); - auto needAnimation = (_content != nullptr) + const auto needAnimation = (_content != nullptr) && (params.animated != anim::type::instant); auto animationParams = SectionSlideParams(); auto newController = createController( @@ -771,8 +771,12 @@ void WrapWidget::showNewContent( newController->takeStepData(_controller.get()); } auto newContent = object_ptr(nullptr); - if (needAnimation) { + const auto enableBackButton = hasBackButton(); + const auto createInAdvance = needAnimation || enableBackButton; + if (createInAdvance) { newContent = createContent(memento, newController.get()); + } + if (needAnimation) { animationParams.withTopBarShadow = hasTopBarShadow() && newContent->hasTopBarShadow(); animationParams.oldContentCache = grabForShowAnimation( @@ -783,7 +787,6 @@ void WrapWidget::showNewContent( if (HasCustomTopBar(_controller.get()) || HasCustomTopBar(newController.get())) { - const auto s = QSize( newContent->width(), animationParams.topSkip); @@ -803,11 +806,10 @@ void WrapWidget::showNewContent( _historyStack.clear(); } - { - if (hasBackButton()) { - newContent->enableBackButton(); - } + if (enableBackButton) { + newContent->enableBackButton(); } + { // Let old controller outlive old content widget. const auto oldController = std::exchange(