libreofficekit/source/gtk/lokdocview.cxx |   16 ++++++----------
 vcl/source/app/svapp.cxx                 |    2 ++
 2 files changed, 8 insertions(+), 10 deletions(-)

New commits:
commit 78b220105cf720590807bc8b509bdeff1743e838
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Fri Oct 28 13:04:00 2022 +0300
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Sun Oct 30 10:00:34 2022 +0100

    lok: You can't assume that destroyView would only destroy one view
    
    In case you have some in-place clients (e.g., Math in-place editing
    is active), destroying the parent view would also destroy children,
    and then both numberOfViewsChanged (called from doc_destroyView)
    must tolerate 0 as a valid input, and lok_doc_view_destroy must
    make sure to destroy the document after the last views had gone.
    
    Change-Id: I32370fea49da0969e1fbbf971a397c4d657ec8f9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141963
    Reviewed-by: Michael Meeks <michael.me...@collabora.com>
    Tested-by: Jenkins
    (cherry picked from commit 616e95c7044e8ea4fe3396dfa22c4ef7e9d4cd32)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141917
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/libreofficekit/source/gtk/lokdocview.cxx 
b/libreofficekit/source/gtk/lokdocview.cxx
index 926f1328ea42..4cb9ef3ea553 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -2772,17 +2772,13 @@ static void lok_doc_view_destroy (GtkWidget* widget)
 
     if (priv->m_pDocument)
     {
-        if (priv->m_pDocument->pClass->getViewsCount(priv->m_pDocument) > 1)
+        // This call may drop several views - e.g., embedded OLE in-place 
clients
+        priv->m_pDocument->pClass->destroyView(priv->m_pDocument, 
priv->m_nViewId);
+        if (priv->m_pDocument->pClass->getViewsCount(priv->m_pDocument) == 0)
         {
-            priv->m_pDocument->pClass->destroyView(priv->m_pDocument, 
priv->m_nViewId);
-        }
-        else
-        {
-            if (priv->m_pDocument)
-            {
-                priv->m_pDocument->pClass->destroy (priv->m_pDocument);
-                priv->m_pDocument = nullptr;
-            }
+            // Last view(s) gone
+            priv->m_pDocument->pClass->destroy (priv->m_pDocument);
+            priv->m_pDocument = nullptr;
             if (priv->m_pOffice)
             {
                 priv->m_pOffice->pClass->destroy (priv->m_pOffice);
diff --git a/vcl/source/app/svapp.cxx b/vcl/source/app/svapp.cxx
index ec66f82d9de6..3579787cacf8 100644
--- a/vcl/source/app/svapp.cxx
+++ b/vcl/source/app/svapp.cxx
@@ -1791,6 +1791,8 @@ bool isUnipoll()
 
 void numberOfViewsChanged(int count)
 {
+    if (count == 0)
+        return;
     ImplSVData * pSVData = ImplGetSVData();
     auto& rCache = pSVData->maGDIData.maScaleCache;
     // Normally the cache size is set to 10, scale according to the number of 
users.

Reply via email to