sw/qa/extras/layout/data/tdf152106.odt |binary
 sw/qa/extras/layout/layout.cxx         |   11 +++++++++++
 sw/source/core/layout/fly.cxx          |    8 ++++++++
 3 files changed, 19 insertions(+)

New commits:
commit 6f0736c2981042f90e83cdd71b3f9c91dbe77661
Author:     László Németh <nem...@numbertext.org>
AuthorDate: Fri Nov 18 14:11:30 2022 +0100
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Sat Nov 19 11:21:11 2022 +0100

    tdf#152106 sw layout: fix freezing of multicol sections with flys
    
    Loading documents with multicol sections with flys could
    freeze Writer. Add loop control for multicol sections to fix it.
    
    Regression from commit 8feac9601cfe35ee0966776bab15d122206f154e
    "tdf#138518 sw: layout: avoid moving flys forward prematurely".
    
    Follow-up to ed12269c42f75f553bb8a8770923406f7824e473
    "tdf#142080 sw: layout: fix infinite loop in CalcContent()".
    
    Change-Id: I06eb3f5a26b2d2ac3999b98a9661112b8bf7738f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142950
    Tested-by: Jenkins
    Reviewed-by: László Németh <nem...@numbertext.org>

diff --git a/sw/qa/extras/layout/data/tdf152106.odt 
b/sw/qa/extras/layout/data/tdf152106.odt
new file mode 100644
index 000000000000..49ef5e50b8bd
Binary files /dev/null and b/sw/qa/extras/layout/data/tdf152106.odt differ
diff --git a/sw/qa/extras/layout/layout.cxx b/sw/qa/extras/layout/layout.cxx
index a5f4c961a602..c84b21f4e5bc 100644
--- a/sw/qa/extras/layout/layout.cxx
+++ b/sw/qa/extras/layout/layout.cxx
@@ -2018,6 +2018,17 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter, TestTdf142080)
         "top", OUString::number(nPage9Top + 1460));
 }
 
+CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf152106)
+{
+    // this caused an infinite loop
+    createSwDoc("tdf152106.odt");
+
+    xmlDocUniquePtr pLayout = parseLayoutDump();
+
+    // frame on page 3
+    assertXPath(pLayout, "/root/page[3]/sorted_objs/fly", 1);
+}
+
 CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf128198)
 {
     createSwDoc("tdf128198-1.docx");
diff --git a/sw/source/core/layout/fly.cxx b/sw/source/core/layout/fly.cxx
index ee779ce678a2..4cee6d9e712d 100644
--- a/sw/source/core/layout/fly.cxx
+++ b/sw/source/core/layout/fly.cxx
@@ -1474,6 +1474,8 @@ void CalcContent( SwLayoutFrame *pLay, bool bNoColl )
 
         // FME 2007-08-30 #i81146# new loop control
         int nLoopControlRuns = 0;
+        // tdf#152106 loop control for multi-column sections
+        int nLoopControlRunsInMultiCol = 0;
         const int nLoopControlMax = 20;
         const SwFrame* pLoopControlCond = nullptr;
 
@@ -1626,10 +1628,16 @@ void CalcContent( SwLayoutFrame *pLay, bool bNoColl )
                 // #i28701# - restart layout process, if
                 // requested by floating screen object formatting
                 if (bRestartLayoutProcess
+                    // tdf#152106 loop control in multi-column sections to 
avoid of freezing
+                    && nLoopControlRunsInMultiCol < nLoopControlMax
                     // tdf#142080 if it was already on next page, and still is,
                     // ignore restart, as restart could cause infinite loop
                     && (wasFrameLowerOfLay || pLay->IsAnLower(pFrame)))
                 {
+                    bool bIsMultiColumn = pSect && pSect->GetSection() && 
pSect->Lower() &&
+                            pSect->Lower()->IsColumnFrame() && 
pSect->Lower()->GetNext();
+                    if ( bIsMultiColumn )
+                        ++nLoopControlRunsInMultiCol;
                     pFrame = pLay->ContainsAny();
                     pAgainObj1 = nullptr;
                     pAgainObj2 = nullptr;

Reply via email to