From 8589a8d8501701e1b93f9752abdaf1740e6d0517 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 13 Sep 2021 17:38:53 +0300 Subject: [PATCH] Try to fix a crash in label click handlers. --- ui/widgets/labels.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/ui/widgets/labels.cpp b/ui/widgets/labels.cpp index ec388b5..dbeb2fc 100644 --- a/ui/widgets/labels.cpp +++ b/ui/widgets/labels.cpp @@ -444,11 +444,15 @@ Text::StateResult FlatLabel::dragActionFinish(const QPoint &p, Qt::MouseButton b _selectionType = TextSelectType::Letters; if (activated) { - const auto guard = window(); - if (!_clickHandlerFilter - || _clickHandlerFilter(activated, button)) { - ActivateClickHandler(guard, activated, button); - } + // _clickHandlerFilter may delete `this`. In that case we don't want + // to try to show a context menu or smth like that. + crl::on_main(this, [=] { + const auto guard = window(); + if (!_clickHandlerFilter + || _clickHandlerFilter(activated, button)) { + ActivateClickHandler(guard, activated, button); + } + }); } if (QGuiApplication::clipboard()->supportsSelection()