Fix a crash in main settings destructor.

Fixes #27544.
This commit is contained in:
John Preston 2024-03-12 23:19:59 +04:00
parent c6f49486ee
commit 8c5db25476
3 changed files with 15 additions and 1 deletions

View File

@ -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();
}

View File

@ -46,6 +46,7 @@ public:
not_null<Window::SessionController*> controller,
not_null<QWidget*> button,
Data::CustomEmojiSizeTag animationSizeTag = {});
[[nodiscard]] bool hasFocus() const;
struct Descriptor {
not_null<Window::SessionController*> controller;

View File

@ -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;