svx/source/accessibility/AccessibleControlShape.cxx |   11 +++++++----
 vcl/inc/unx/gtk/gtkdata.hxx                         |    5 +++--
 vcl/unx/gtk3/a11y/atkutil.cxx                       |   19 ++++++++++++-------
 3 files changed, 22 insertions(+), 13 deletions(-)

New commits:
commit a12633a9982d34eb8f0b714d5f25cff3040f33ab
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Mon May 29 09:50:33 2023 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Mon May 29 12:53:13 2023 +0200

    tdf#155515 tdf#155528 crash on exit
    
    regression from
        commit 3b7db802731826b6cc3b55100470b0c61c1f2dfa
        Author: Noel Grandin <noel.gran...@collabora.co.uk>
        Date:   Thu May 4 10:06:14 2023 +0200
        tdf#105404 [API CHANGE] add index to accessiblity change event
    
    Fix a handful of things related to accessibility objects being
    destructed later than they should and consequently trying at access
    other stuff that has already been destructed.
    
    (1) AccessibleControlShape::disposing check the window still exists
    (2) DocumentFocusListener::notifyEvent, handle INVALIDATE_ALL_CHILDREN
    (3) hold DocumentFocusListener by weak reference in GtkSalData, so that
    it dies when the related UI widgets die
    
    Change-Id: I38bf68a748b37e6abc4a8cfcc961436728e081bd
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152365
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/svx/source/accessibility/AccessibleControlShape.cxx 
b/svx/source/accessibility/AccessibleControlShape.cxx
index bf085bb753a4..8fe42db6dada 100644
--- a/svx/source/accessibility/AccessibleControlShape.cxx
+++ b/svx/source/accessibility/AccessibleControlShape.cxx
@@ -629,11 +629,14 @@ void SAL_CALL AccessibleControlShape::disposing()
     if ( m_bWaitingForControl )
     {
         OSL_FAIL( "AccessibleControlShape::disposing: this should never 
happen!" );
-        Reference< XContainer > xContainer = lcl_getControlContainer( 
maShapeTreeInfo.GetWindow()->GetOutDev(), maShapeTreeInfo.GetSdrView() );
-        if ( xContainer.is() )
+        if (auto pWindow = maShapeTreeInfo.GetWindow())
         {
-            m_bWaitingForControl = false;
-            xContainer->removeContainerListener( this );
+            Reference< XContainer > xContainer = lcl_getControlContainer( 
pWindow->GetOutDev(), maShapeTreeInfo.GetSdrView() );
+            if ( xContainer.is() )
+            {
+                m_bWaitingForControl = false;
+                xContainer->removeContainerListener( this );
+            }
         }
     }
 
diff --git a/vcl/inc/unx/gtk/gtkdata.hxx b/vcl/inc/unx/gtk/gtkdata.hxx
index b39d5dc1aacf..cd03de599887 100644
--- a/vcl/inc/unx/gtk/gtkdata.hxx
+++ b/vcl/inc/unx/gtk/gtkdata.hxx
@@ -38,6 +38,7 @@
 #include <osl/conditn.hxx>
 #include <saltimer.hxx>
 #include <o3tl/enumarray.hxx>
+#include <unotools/weakref.hxx>
 
 #include <exception>
 #include <string_view>
@@ -283,13 +284,13 @@ class GtkSalData final : public GenericUnixSalData
     osl::Condition  m_aDispatchCondition;
     std::exception_ptr m_aException;
 
-    rtl::Reference<DocumentFocusListener> m_xDocumentFocusListener;
+    unotools::WeakReference<DocumentFocusListener> m_xDocumentFocusListener;
 
 public:
     GtkSalData();
     virtual ~GtkSalData() override;
 
-    DocumentFocusListener & GetDocumentFocusListener();
+    rtl::Reference<DocumentFocusListener> GetDocumentFocusListener();
 
     void Init();
     virtual void Dispose() override;
diff --git a/vcl/unx/gtk3/a11y/atkutil.cxx b/vcl/unx/gtk3/a11y/atkutil.cxx
index b16648ecbf0e..fc15351374fd 100644
--- a/vcl/unx/gtk3/a11y/atkutil.cxx
+++ b/vcl/unx/gtk3/a11y/atkutil.cxx
@@ -162,8 +162,11 @@ void DocumentFocusListener::notifyEvent( const 
accessibility::AccessibleEventObj
             }
 
             case accessibility::AccessibleEventId::INVALIDATE_ALL_CHILDREN:
-                SAL_INFO("vcl.a11y", "Invalidate all children called");
+            {
+                if (uno::Reference< accessibility::XAccessible > xAcc = 
getAccessible(aEvent))
+                    detachRecursive(xAcc);
                 break;
+            }
 
             default:
                 break;
@@ -433,13 +436,15 @@ WindowList g_aWindowList;
 
 }
 
-DocumentFocusListener & GtkSalData::GetDocumentFocusListener()
+rtl::Reference<DocumentFocusListener> GtkSalData::GetDocumentFocusListener()
 {
-    if (!m_xDocumentFocusListener)
+    rtl::Reference<DocumentFocusListener> xDFL = 
m_xDocumentFocusListener.get();
+    if (!xDFL)
     {
-        m_xDocumentFocusListener = new DocumentFocusListener;
+        xDFL = new DocumentFocusListener;
+        m_xDocumentFocusListener = xDFL.get();
     }
-    return *m_xDocumentFocusListener;
+    return xDFL;
 }
 
 static void handle_get_focus(::VclWindowEvent const * pEvent)
@@ -447,7 +452,7 @@ static void handle_get_focus(::VclWindowEvent const * 
pEvent)
     GtkSalData *const pSalData(GetGtkSalData());
     assert(pSalData);
 
-    DocumentFocusListener & 
rDocumentFocusListener(pSalData->GetDocumentFocusListener());
+    rtl::Reference<DocumentFocusListener> 
xDocumentFocusListener(pSalData->GetDocumentFocusListener());
 
     vcl::Window *pWindow = pEvent->GetWindow();
 
@@ -493,7 +498,7 @@ static void handle_get_focus(::VclWindowEvent const * 
pEvent)
         {
             try
             {
-                rDocumentFocusListener.attachRecursive(xAccessible, xContext, 
nStateSet);
+                xDocumentFocusListener->attachRecursive(xAccessible, xContext, 
nStateSet);
             }
             catch (const uno::Exception&)
             {

Reply via email to