From 8c5db25476b08f5b1e2562ac8eb99895880ee801 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 12 Mar 2024 23:19:59 +0400 Subject: [PATCH] Fix a crash in main settings destructor. Fixes #27544. --- .../info/profile/info_profile_emoji_status_panel.cpp | 4 ++++ .../info/profile/info_profile_emoji_status_panel.h | 1 + Telegram/SourceFiles/settings/settings_main.cpp | 11 ++++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/info/profile/info_profile_emoji_status_panel.cpp b/Telegram/SourceFiles/info/profile/info_profile_emoji_status_panel.cpp index c7f26b4ef..c4cce455f 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_emoji_status_panel.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_emoji_status_panel.cpp @@ -159,6 +159,10 @@ void EmojiStatusPanel::show(Descriptor &&descriptor) { _panel->toggleAnimated(); } +bool EmojiStatusPanel::hasFocus() const { + return _panel && Ui::InFocusChain(_panel.get()); +} + void EmojiStatusPanel::repaint() { _panel->selector()->update(); } diff --git a/Telegram/SourceFiles/info/profile/info_profile_emoji_status_panel.h b/Telegram/SourceFiles/info/profile/info_profile_emoji_status_panel.h index a373c904c..9777cfcfa 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_emoji_status_panel.h +++ b/Telegram/SourceFiles/info/profile/info_profile_emoji_status_panel.h @@ -46,6 +46,7 @@ public: not_null controller, not_null button, Data::CustomEmojiSizeTag animationSizeTag = {}); + [[nodiscard]] bool hasFocus() const; struct Descriptor { not_null controller; diff --git a/Telegram/SourceFiles/settings/settings_main.cpp b/Telegram/SourceFiles/settings/settings_main.cpp index c746a881a..33b175520 100644 --- a/Telegram/SourceFiles/settings/settings_main.cpp +++ b/Telegram/SourceFiles/settings/settings_main.cpp @@ -174,7 +174,16 @@ Cover::Cover( }, _name->lifetime()); } -Cover::~Cover() = default; +Cover::~Cover() { + if (_emojiStatusPanel.hasFocus()) { + // Panel will try to return focus to the layer widget, the problem is + // we are destroying the layer widget probably right now and focusing + // it will lead to a crash, because it destroys its children (how we + // got here) after it clears focus out of itself. So if you return + // the focus inside a child destructor, it won't be cleared at all. + window()->setFocus(); + } +} void Cover::setupChildGeometry() { using namespace rpl::mappers;