[Libreoffice-commits] core.git: include/sfx2 sfx2/source

Szymon KÅ‚os (via logerrit) logerrit at kemper.freedesktop.org
Wed Aug 18 11:19:13 UTC 2021


 include/sfx2/sidebar/SidebarController.hxx |    2 ++
 sfx2/source/sidebar/SidebarController.cxx  |   10 ++++++----
 sfx2/source/sidebar/Theme.cxx              |    6 +++++-
 3 files changed, 13 insertions(+), 5 deletions(-)

New commits:
commit e34ec3e196b3265ea640e1730c7d42dd6182e65f
Author:     Szymon Kłos <szymon.klos at collabora.com>
AuthorDate: Thu Jul 15 10:35:24 2021 +0200
Commit:     Szymon Kłos <szymon.klos at collabora.com>
CommitDate: Wed Aug 18 13:18:36 2021 +0200

    Don't crash on SidebarController dispose when app is closing
    
    When app is closing it is possible SfxGetpApp() will return null. So
    GetCurrentTheme() cannot return reference to correct theme.
    Remember which theme has registered SidebarController to unregister when
    disposing.
    
    Change-Id: If223233f621601f445472b0413a56e9c51e59673
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118970
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Pranam Lashkari <lpranam at collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120630
    Tested-by: Jenkins
    Reviewed-by: Szymon Kłos <szymon.klos at collabora.com>

diff --git a/include/sfx2/sidebar/SidebarController.hxx b/include/sfx2/sidebar/SidebarController.hxx
index 133c1f5806c6..3df8d8fb2e45 100644
--- a/include/sfx2/sidebar/SidebarController.hxx
+++ b/include/sfx2/sidebar/SidebarController.hxx
@@ -29,6 +29,7 @@
 #include <sfx2/sidebar/TabBar.hxx>
 #include <sfx2/viewfrm.hxx>
 
+#include <com/sun/star/beans/XPropertySet.hpp>
 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
 #include <com/sun/star/frame/XStatusListener.hpp>
 #include <com/sun/star/frame/XFrameActionListener.hpp>
@@ -194,6 +195,7 @@ private:
     OUString msCurrentDeckId;
     AsynchronousCall maPropertyChangeForwarder;
     AsynchronousCall maContextChangeUpdate;
+    css::uno::Reference<css::beans::XPropertySet> mxThemePropertySet;
 
     /** Two flags control whether the deck is displayed or if only the
         tab bar remains visible.
diff --git a/sfx2/source/sidebar/SidebarController.cxx b/sfx2/source/sidebar/SidebarController.cxx
index 803d1c10a739..c03b2a96acdb 100644
--- a/sfx2/source/sidebar/SidebarController.cxx
+++ b/sfx2/source/sidebar/SidebarController.cxx
@@ -157,7 +157,8 @@ rtl::Reference<SidebarController> SidebarController::create(SidebarDockingWindow
     instance->mpParentWindow->AddEventListener(LINK(instance.get(), SidebarController, WindowEventHandler));
 
     // Listen for theme property changes.
-    Theme::GetPropertySet()->addPropertyChangeListener(
+    instance->mxThemePropertySet = Theme::GetPropertySet();
+    instance->mxThemePropertySet->addPropertyChangeListener(
         "",
         static_cast<css::beans::XPropertyChangeListener*>(instance.get()));
 
@@ -312,9 +313,10 @@ void SAL_CALL SidebarController::disposing()
     if (mxReadOnlyModeDispatch.is())
         mxReadOnlyModeDispatch->removeStatusListener(this, Tools::GetURL(gsReadOnlyCommandName));
 
-    Theme::GetPropertySet()->removePropertyChangeListener(
-        "",
-        static_cast<css::beans::XPropertyChangeListener*>(this));
+    if (mxThemePropertySet.is())
+        mxThemePropertySet->removePropertyChangeListener(
+            "",
+            static_cast<css::beans::XPropertyChangeListener*>(this));
 
     if (mpParentWindow != nullptr)
     {
diff --git a/sfx2/source/sidebar/Theme.cxx b/sfx2/source/sidebar/Theme.cxx
index cd4ce36bd658..6d6fe7bc517f 100644
--- a/sfx2/source/sidebar/Theme.cxx
+++ b/sfx2/source/sidebar/Theme.cxx
@@ -32,6 +32,7 @@ namespace sfx2::sidebar {
 
 Theme& Theme::GetCurrentTheme()
 {
+    OSL_ASSERT(SfxGetpApp());
     return SfxGetpApp()->GetSidebarTheme();
 }
 
@@ -177,7 +178,10 @@ void SAL_CALL Theme::disposing()
 
 Reference<beans::XPropertySet> Theme::GetPropertySet()
 {
-    return Reference<beans::XPropertySet>(static_cast<XWeak*>(&GetCurrentTheme()), UNO_QUERY);
+    if (SfxGetpApp())
+        return Reference<beans::XPropertySet>(static_cast<XWeak*>(&GetCurrentTheme()), UNO_QUERY);
+    else
+        return Reference<beans::XPropertySet>();
 }
 
 Reference<beans::XPropertySetInfo> SAL_CALL Theme::getPropertySetInfo()


More information about the Libreoffice-commits mailing list