From 48a8901a205000e9878c7ee5b4fb26e07ea0a607 Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Fri, 29 Jan 2021 15:09:59 +0900 Subject: tdf#139767 fix crash caused by the selection listener MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When development tools window was closed, the selection listener was still listening and tried to change the selection because it was never unregistered from the selection supplier. This caused a crash as it tried to change the object on an non existing tree view. This change modifies the selection change listener so that is adds itself to the selection supplier when constructed and removes itself from the selection supplier, when the development tools window is disposed. Change-Id: Ifcb56aaee8f3c5c71ec609e68ffc78573f1b4179 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110121 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- .../devtools/DevelopmentToolDockingWindow.cxx | 36 ++++++++++++++-------- 1 file changed, 24 insertions(+), 12 deletions(-) (limited to 'svx') diff --git a/svx/source/devtools/DevelopmentToolDockingWindow.cxx b/svx/source/devtools/DevelopmentToolDockingWindow.cxx index c6adf1f5f0a5..40e5bcc76857 100644 --- a/svx/source/devtools/DevelopmentToolDockingWindow.cxx +++ b/svx/source/devtools/DevelopmentToolDockingWindow.cxx @@ -34,13 +34,11 @@ #include #include -#include +#include #include #include -#include - using namespace css; namespace @@ -62,6 +60,7 @@ public: , mxController(rxController) , mpDockingWindow(pDockingWindow) { + connect(); } ~SelectionChangeHandler() { mpDockingWindow.disposeAndClear(); } @@ -76,6 +75,19 @@ public: mpDockingWindow->selectionChanged(xInterface); } } + + void connect() + { + uno::Reference xSupplier(mxController, uno::UNO_QUERY); + xSupplier->addSelectionChangeListener(this); + } + + void disconnect() + { + uno::Reference xSupplier(mxController, uno::UNO_QUERY); + xSupplier->removeSelectionChangeListener(this); + } + virtual void SAL_CALL disposing(const css::lang::EventObject& /*rEvent*/) override {} virtual void SAL_CALL disposing() override {} @@ -110,14 +122,7 @@ DevelopmentToolDockingWindow::DevelopmentToolDockingWindow(SfxBindings* pInputBi introspect(mxRoot); maDocumentModelTreeHandler.inspectDocument(); - - uno::Reference xSupplier(xController, uno::UNO_QUERY); - if (xSupplier.is()) - { - uno::Reference xChangeListener( - new SelectionChangeHandler(xController, this)); - xSupplier->addSelectionChangeListener(xChangeListener); - } + mxSelectionListener.set(new SelectionChangeHandler(xController, this)); } IMPL_LINK(DevelopmentToolDockingWindow, LeftSideSelected, weld::TreeView&, rView, void) @@ -140,10 +145,17 @@ DevelopmentToolDockingWindow::~DevelopmentToolDockingWindow() { disposeOnce(); } void DevelopmentToolDockingWindow::dispose() { + auto* pSelectionChangeHandler + = dynamic_cast(mxSelectionListener.get()); + if (pSelectionChangeHandler) + pSelectionChangeHandler->disconnect(); + + mxSelectionListener = uno::Reference(); + maDocumentModelTreeHandler.dispose(); + mpClassNameLabel.reset(); mpClassListBox.reset(); mpSelectionToggle.reset(); - maDocumentModelTreeHandler.dispose(); mpLeftSideTreeView.reset(); SfxDockingWindow::dispose(); -- cgit