sw/source/core/view/vdraw.cxx |   49 ++++++++++++++++++++++++------------------
 1 file changed, 28 insertions(+), 21 deletions(-)

New commits:
commit 71a9de600abb46e9f8bf61fd3c139dd895c60c28
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Fri Dec 13 11:33:25 2024 +0000
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Fri Dec 13 14:44:52 2024 +0100

    crashtesting: assert on reimport of docx export of ooo102874-2.doc
    
     #0  SdrObjList::RemoveObjectFromContainer (this=0x1d12e30, 
nObjectPosition=3) at core/svx/source/svdraw/svdpage.cxx:1093
     #1  0x00007ffff15da0bd in SdrObjList::SetObjectOrdNum (this=0x1d12e30, 
nOldObjNum=3, nNewObjNum=2) at core/svx/source/svdraw/svdpage.cxx:536
     #2  0x00007ffff14c954c in SdrObject::ensureSortedImmediatelyAfter 
(this=0x4f56d30, rFirst=...) at core/svx/source/svdraw/svdobj.cxx:897
     #3  0x00007fffcdc4978c in SwTextBoxHelper::DoTextBoxZOrderCorrection 
(pShape=0x4c3a660, pObj=0x4c3d730) at 
core/sw/source/core/doc/textboxhelper.cxx:1638
     #4  0x00007fffcdc4bcbc in SwTextBoxHelper::changeAnchor (pShape=0x4c3a660, 
pObj=0x4c3d730) at core/sw/source/core/doc/textboxhelper.cxx:1247
     #5  0x00007fffcdc4e613 in SwTextBoxHelper::synchronizeGroupTextBoxProperty
         (pFunc=0x7fffcdc4bc10 <SwTextBoxHelper::changeAnchor(SwFrameFormat*, 
SdrObject*)>, pFormat=0x4c3a660, pObj=0x4c3d730)
         at core/sw/source/core/doc/textboxhelper.cxx:1652
     #6  0x00007fffcdd41a89 in SwDrawContact::Changed_ (this=0x4c55400, 
rObj=..., eType=SdrUserCallType::ChildMoveOnly, pOldBoundRect=0x7fffffff09d8)
         at core/sw/source/core/draw/dcontact.cxx:1250
     #7  0x00007fffcdd410a7 in SwDrawContact::Changed (this=0x4c55400, 
rObj=..., eType=SdrUserCallType::ChildMoveOnly, rOldBoundRect=...)
         at core/sw/source/core/draw/dcontact.cxx:1005
     #8  0x00007ffff14c7356 in SdrObject::SendUserCall (this=0x4c3d730, 
eUserCall=SdrUserCallType::MoveOnly, rBoundRect=...) at 
core/svx/source/svdraw/svdobj.cxx:2827
     #9  0x00007ffff14b11d8 in SdrObjCustomShape::Move (this=0x4c3d730, 
rSiz=Size = {...}) at core/svx/source/svdraw/svdoashp.cxx:1499
     #10 0x00007ffff152753b in SdrObjGroup::Move (this=0x1be18e0, rSiz=Size = 
{...}) at core/svx/source/svdraw/svdogrp.cxx:561
     #11 0x00007fffce8c80b8 in SwViewShellImp::NotifySizeChg
         
(unique_ptrI7SdrMarkSt14default_deleteIS2_EESaIS5_EE11_M_allocateEm=<error 
reading variable: Unhandled DWARF expression opcode 0x0>, hrowE=<error reading 
variable: Unhandled DWARF expression opcode 0x0>) at 
core/sw/source/core/view/vdraw.cxx:274
     #12 0x00007fffce032bc1 in AdjustSizeChgNotify (pRoot=0x5e1c7f0) at 
core/sw/source/core/layout/pagechg.cxx:851
     #13 0x00007fffce03243f in SwRootFrame::CheckViewLayout (this=0x5e1c7f0, 
pViewOpt=0x0, pVisArea=0x0) at core/sw/source/core/layout/pagechg.cxx:2445
     #14 0x00007fffce032eec in SwPageFrame::Cut (this=0x5f19910) at 
core/sw/source/core/layout/pagechg.cxx:921
     #15 0x00007fffce037d40 in SwRootFrame::RemovePage (this=0x5e1c7f0, 
pDelRef=0x7fffffff13c0, eResult=SwRemoveResult::Prev)
         at core/sw/source/core/layout/pagechg.cxx:1518
     #16 0x00007fffce03808e in SwRootFrame::RemoveSuperfluous (this=0x5e1c7f0) 
at core/sw/source/core/layout/pagechg.cxx:1557
     #17 0x00007fffcdfe8d04 in SwLayAction::InternalAction 
(this=0x7fffffff1a30, pRenderContext=0x5211510) at 
core/sw/source/core/layout/layact.cxx:694
     #18 0x00007fffcdfe7cc6 in SwLayAction::Action (this=0x7fffffff1a30, 
pRenderContext=0x5211510) at core/sw/source/core/layout/layact.cxx:396
     #19 0x00007fffce8d5995 in SwViewShell::CalcLayout (this=0x521c540) at 
core/sw/source/core/view/viewsh.cxx:1197
     #20 0x00007fffcde1233f in SwEditShell::CalcLayout (this=0x521c540) at 
core/sw/source/core/edit/edws.cxx:111
    
    Change-Id: I66ffbbfc74e52eea2e24e486d52607e84ffb8fcb
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178415
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/sw/source/core/view/vdraw.cxx b/sw/source/core/view/vdraw.cxx
index d4529bb650d8..2d621476c4b4 100644
--- a/sw/source/core/view/vdraw.cxx
+++ b/sw/source/core/view/vdraw.cxx
@@ -212,6 +212,7 @@ void SwViewShellImp::NotifySizeChg( const Size &rNewSz )
 
     OSL_ENSURE( m_pShell->getIDocumentDrawModelAccess().GetDrawModel(), 
"NotifySizeChg without DrawModel" );
     SdrPage* pPage = 
m_pShell->getIDocumentDrawModelAccess().GetDrawModel()->GetPage( 0 );
+    std::vector<SdrObject*> aCandidatesToMove;
     for (const rtl::Reference<SdrObject>& pObj : *pPage)
     {
         if( dynamic_cast<const SwVirtFlyDrawObj*>( pObj.get()) ==  nullptr )
@@ -252,27 +253,33 @@ void SwViewShellImp::NotifySizeChg( const Size &rNewSz )
                 continue;
             }
 
-            const tools::Rectangle aObjBound( pObj->GetCurrentBoundRect() );
-            if ( !aDocRect.Contains( aObjBound ) )
-            {
-                Size aSz;
-                if ( aObjBound.Left() > aDocRect.Right() )
-                    aSz.setWidth( (aDocRect.Right() - aObjBound.Left()) - 
MINFLY );
-                if ( aObjBound.Top() > aDocRect.Bottom() )
-                    aSz.setHeight( (aDocRect.Bottom() - aObjBound.Top()) - 
MINFLY );
-                if ( aSz.Width() || aSz.Height() )
-                    pObj->Move( aSz );
-
-                // Don't let large objects disappear to the top
-                aSz.setWidth(0);
-                aSz.setHeight(0);
-                if ( aObjBound.Right() < aDocRect.Left() )
-                    aSz.setWidth( (aDocRect.Left() - aObjBound.Right()) + 
MINFLY );
-                if ( aObjBound.Bottom() < aDocRect.Top() )
-                    aSz.setHeight( (aDocRect.Top() - aObjBound.Bottom()) + 
MINFLY );
-                if ( aSz.Width() || aSz.Height() )
-                    pObj->Move( aSz );
-            }
+            aCandidatesToMove.push_back(pObj.get());
+        }
+    }
+
+    // Moving a SdrObject can invalidate their positions in SdrPage's 
container of objects
+    for (const auto pObj : aCandidatesToMove)
+    {
+        const tools::Rectangle aObjBound( pObj->GetCurrentBoundRect() );
+        if ( !aDocRect.Contains( aObjBound ) )
+        {
+            Size aSz;
+            if ( aObjBound.Left() > aDocRect.Right() )
+                aSz.setWidth( (aDocRect.Right() - aObjBound.Left()) - MINFLY );
+            if ( aObjBound.Top() > aDocRect.Bottom() )
+                aSz.setHeight( (aDocRect.Bottom() - aObjBound.Top()) - MINFLY 
);
+            if ( aSz.Width() || aSz.Height() )
+                pObj->Move( aSz );
+
+            // Don't let large objects disappear to the top
+            aSz.setWidth(0);
+            aSz.setHeight(0);
+            if ( aObjBound.Right() < aDocRect.Left() )
+                aSz.setWidth( (aDocRect.Left() - aObjBound.Right()) + MINFLY );
+            if ( aObjBound.Bottom() < aDocRect.Top() )
+                aSz.setHeight( (aDocRect.Top() - aObjBound.Bottom()) + MINFLY 
);
+            if ( aSz.Width() || aSz.Height() )
+                pObj->Move( aSz );
         }
     }
 }

Reply via email to