[Libreoffice-commits] core.git: toolkit/source vcl/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Wed May 19 17:21:09 UTC 2021


 toolkit/source/helper/unowrapper.cxx |   24 ++++++++++++++++--------
 vcl/source/window/window.cxx         |    5 +++++
 2 files changed, 21 insertions(+), 8 deletions(-)

New commits:
commit 6989c3df0facf3a5cb373942c337cbc7879fc0db
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Wed May 19 15:24:42 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Wed May 19 19:20:32 2021 +0200

    fix crash in X-Ray extension
    
    caused by
        commit 883b7a34d288410ac6f820e91d9eaa65ba2b9cb1
        DBG_ASSERT->assert in UnoWrapper
    
    No idea why X-ray is triggering this, but it seems to work when I dial
    it back to a SAL_WARN again
    
    And also caused by
        commit 5aa60be574ece81b27c8f63e6e809871c694dba0
        fix leak in VCLXWindow
    
    So disconnect the toolkit-window-peer from the vcl::Window before
    disposing the peer.
    
    Change-Id: I3310b76c1affc13c53c1e23810e383a8d2152ec7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115806
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/toolkit/source/helper/unowrapper.cxx b/toolkit/source/helper/unowrapper.cxx
index 8474b45399c4..a83cd540ba5e 100644
--- a/toolkit/source/helper/unowrapper.cxx
+++ b/toolkit/source/helper/unowrapper.cxx
@@ -170,16 +170,24 @@ void UnoWrapper::SetWindowInterface( vcl::Window* pWindow, const css::uno::Refer
     if ( !pVCLXWindow )
         return;
 
-    css::uno::Reference< css::awt::XWindowPeer> xPeer = pWindow->GetWindowPeer();
-    if( xPeer.is() )
+    if (!pWindow)
+    {
+        // we are disconnecting a peer from a window
+        pVCLXWindow->SetWindow( nullptr );
+    }
+    else
     {
-        bool bSameInstance( pVCLXWindow == dynamic_cast< VCLXWindow* >( xPeer.get() ));
-        assert( bSameInstance && "UnoWrapper::SetWindowInterface: there is already a WindowPeer/ComponentInterface for this VCL window" );
-        if ( bSameInstance )
-            return;
+        css::uno::Reference< css::awt::XWindowPeer> xPeer = pWindow->GetWindowPeer();
+        if( xPeer.is() )
+        {
+            bool bSameInstance( pVCLXWindow == dynamic_cast< VCLXWindow* >( xPeer.get() ));
+            SAL_WARN_IF( !bSameInstance, "toolkit.helper", "UnoWrapper::SetWindowInterface: there is already a WindowPeer/ComponentInterface for this VCL window" );
+            if ( bSameInstance )
+                return;
+        }
+        pVCLXWindow->SetWindow( pWindow );
+        pWindow->SetWindowPeer( xIFace, pVCLXWindow );
     }
-    pVCLXWindow->SetWindow( pWindow );
-    pWindow->SetWindowPeer( xIFace, pVCLXWindow );
 }
 
 css::uno::Reference<css::awt::XPopupMenu> UnoWrapper::CreateMenuInterface( PopupMenu* pPopupMenu )
diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx
index 0a279983d02d..fa3cb12133d5 100644
--- a/vcl/source/window/window.cxx
+++ b/vcl/source/window/window.cxx
@@ -3129,6 +3129,11 @@ void Window::SetWindowPeer( Reference< css::awt::XWindowPeer > const & xPeer, VC
     // be safe against re-entrance: first clear the old ref, then assign the new one
     if (mpWindowImpl->mxWindowPeer)
     {
+        // first, disconnect the peer from ourself, otherwise disposing it, will dispose us
+        UnoWrapperBase* pWrapper = UnoWrapperBase::GetUnoWrapper();
+        SAL_WARN_IF( !pWrapper, "vcl.window", "SetComponentInterface: No Wrapper!" );
+        if ( pWrapper )
+            pWrapper->SetWindowInterface( nullptr, mpWindowImpl->mxWindowPeer );
         mpWindowImpl->mxWindowPeer->dispose();
         mpWindowImpl->mxWindowPeer.clear();
     }


More information about the Libreoffice-commits mailing list