From bef36eed84bbc1663b174a082d0d3e6544aaab88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= Date: Wed, 26 Oct 2022 10:34:32 +0100 Subject: [PATCH] crashreporting: crash in thesaurus dialog PostUserEvent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit not reproducible, but a common error to post an event that outlives the owner Change-Id: Ic2633c504d853116d03e3322f552ae66e7e7e14e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141869 Tested-by: Jenkins Reviewed-by: Caolán McNamara --- cui/source/dialogs/thesdlg.cxx | 14 +++++++++++--- cui/source/inc/thesdlg.hxx | 3 +++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/cui/source/dialogs/thesdlg.cxx b/cui/source/dialogs/thesdlg.cxx index a9f4883f4c70..1d98480973ee 100644 --- a/cui/source/dialogs/thesdlg.cxx +++ b/cui/source/dialogs/thesdlg.cxx @@ -165,8 +165,8 @@ void SvxThesaurusDialog::LookUp_Impl() m_xAlternativesCT->set_visible(m_bWordFound); m_xNotFound->set_visible(!m_bWordFound); - if (m_bWordFound) - Application::PostUserEvent(LINK(this, SvxThesaurusDialog, SelectFirstHdl_Impl)); + if (m_bWordFound && !m_nSelectFirstEvent) + m_nSelectFirstEvent = Application::PostUserEvent(LINK(this, SvxThesaurusDialog, SelectFirstHdl_Impl)); if (m_xWordCB->find_text(aText) == -1) m_xWordCB->append_text(aText); @@ -217,13 +217,15 @@ IMPL_LINK( SvxThesaurusDialog, AlternativesDoubleClickHdl_Impl, weld::TreeView&, //! workaround to set the selection since calling SelectEntryPos within //! the double click handler does not work - Application::PostUserEvent(LINK(this, SvxThesaurusDialog, SelectFirstHdl_Impl)); + if (!m_nSelectFirstEvent) + m_nSelectFirstEvent = Application::PostUserEvent(LINK(this, SvxThesaurusDialog, SelectFirstHdl_Impl)); return true; } IMPL_LINK_NOARG(SvxThesaurusDialog, SelectFirstHdl_Impl, void *, void) { + m_nSelectFirstEvent = nullptr; if (m_xAlternativesCT->n_children() >= 2) { m_xAlternativesCT->select(1); // pos 0 is a 'header' that is not selectable @@ -249,6 +251,7 @@ SvxThesaurusDialog::SvxThesaurusDialog( , m_xReplaceEdit(m_xBuilder->weld_entry("replaceed")) , m_xLangLB(m_xBuilder->weld_combo_box("langcb")) , m_xReplaceBtn(m_xBuilder->weld_button("ok")) + , m_nSelectFirstEvent(nullptr) { m_aModifyIdle.SetInvokeHandler( LINK( this, SvxThesaurusDialog, ModifyTimer_Hdl ) ); m_aModifyIdle.SetPriority( TaskPriority::LOWEST ); @@ -316,6 +319,11 @@ SvxThesaurusDialog::SvxThesaurusDialog( SvxThesaurusDialog::~SvxThesaurusDialog() { + if (m_nSelectFirstEvent) + { + Application::RemoveUserEvent(m_nSelectFirstEvent); + m_nSelectFirstEvent = nullptr; + } } IMPL_LINK_NOARG(SvxThesaurusDialog, ReplaceBtnHdl_Impl, weld::Button&, void) diff --git a/cui/source/inc/thesdlg.hxx b/cui/source/inc/thesdlg.hxx index de085d678682..05865d68d92f 100644 --- a/cui/source/inc/thesdlg.hxx +++ b/cui/source/inc/thesdlg.hxx @@ -26,6 +26,8 @@ #include #include +struct ImplSVEvent; + class SvxThesaurusDialog : public SfxDialogController { Idle m_aModifyIdle; @@ -43,6 +45,7 @@ class SvxThesaurusDialog : public SfxDialogController std::unique_ptr m_xReplaceEdit; std::unique_ptr m_xLangLB; std::unique_ptr m_xReplaceBtn; + ImplSVEvent* m_nSelectFirstEvent; public: virtual ~SvxThesaurusDialog() override;