From 9d3715a36a6b1df65121e2418bb9f914881d59e3 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 13 Feb 2023 06:09:53 +0400 Subject: [PATCH] Fix possible crash in members invite. In some cases Info::Controller (public Window::SessionNavigation) can be destroyed without the box being destroyed, for example when group topics are turned on and off. --- .../boxes/peers/add_participants_box.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp b/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp index c34ab298df..9f9f7ea937 100644 --- a/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp @@ -295,10 +295,11 @@ void AddParticipantsBoxController::Start( not_null chat) { auto controller = std::make_unique(chat); const auto weak = controller.get(); + const auto parent = navigation->parentController(); auto initBox = [=](not_null box) { box->addButton(tr::lng_participant_invite(), [=] { weak->inviteSelectedUsers(box, [=] { - navigation->parentController()->showPeerHistory( + parent->showPeerHistory( chat, Window::SectionShow::Way::ClearStack, ShowAtTheEndMsgId); @@ -320,11 +321,12 @@ void AddParticipantsBoxController::Start( channel, std::move(alreadyIn)); const auto weak = controller.get(); + const auto parent = navigation->parentController(); auto initBox = [=](not_null box) { box->addButton(tr::lng_participant_invite(), [=] { weak->inviteSelectedUsers(box, [=] { if (channel->isMegagroup()) { - navigation->parentController()->showPeerHistory( + parent->showPeerHistory( channel, Window::SectionShow::Way::ClearStack, ShowAtTheEndMsgId); @@ -337,13 +339,16 @@ void AddParticipantsBoxController::Start( justCreated ? tr::lng_create_group_skip() : tr::lng_cancel(), [=] { box->closeBox(); }); if (justCreated) { + const auto weak = base::make_weak(parent); box->boxClosing() | rpl::start_with_next([=] { auto params = Window::SectionShow(); params.activation = anim::activation::background; - navigation->parentController()->showPeerHistory( - channel, - params, - ShowAtTheEndMsgId); + if (const auto strong = weak.get()) { + strong->showPeerHistory( + channel, + params, + ShowAtTheEndMsgId); + } }, box->lifetime()); } };