sw/source/uibase/shells/frmsh.cxx |   14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

New commits:
commit a5154c0de7679e2abc78b33b351025ea5e54a479
Author:     Miklos Vajna <[email protected]>
AuthorDate: Tue Jul 29 08:47:32 2025 +0200
Commit:     Miklos Vajna <[email protected]>
CommitDate: Tue Jul 29 13:01:32 2025 +0200

    sw: fix assertion failure in SwFrameShell::Execute()
    
    Open e.g. the tdf#167222 bugdoc, right-click on the only fly frame in
    the document -> Properties -> crash:
    
    soffice.bin: include/editeng/sizeitem.hxx:66: void 
SvxSizeItem::SetWidth(tools::Long): Assertion `!GetRefCount() && "ERROR: 
RefCounted SfxPoolItem CANNOT be changed (!)"' failed.
    
    So instead make a copy, mutate that copy and put it back to the item
    set. This also eliminates an unwanted const_cast().
    
    Change-Id: I49634af7ebbe93e89edd2a770750fd6f11fd244b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/188523
    Reviewed-by: Miklos Vajna <[email protected]>
    Tested-by: Jenkins

diff --git a/sw/source/uibase/shells/frmsh.cxx 
b/sw/source/uibase/shells/frmsh.cxx
index 53ff92e59d11..5d46cdaf22c8 100644
--- a/sw/source/uibase/shells/frmsh.cxx
+++ b/sw/source/uibase/shells/frmsh.cxx
@@ -492,11 +492,15 @@ void SwFrameShell::Execute(SfxRequest &rReq)
                 aSet.SetParent( aMgr.GetAttrSet().GetParent() );
 
                 // On % values initialize size
-                SwFormatFrameSize& rSize = 
const_cast<SwFormatFrameSize&>(aSet.Get(RES_FRM_SIZE));
-                if (rSize.GetWidthPercent() && rSize.GetWidthPercent() != 
SwFormatFrameSize::SYNCED)
-                    
rSize.SetWidth(rSh.GetAnyCurRect(CurRectType::FlyEmbedded).Width());
-                if (rSize.GetHeightPercent() && rSize.GetHeightPercent() != 
SwFormatFrameSize::SYNCED)
-                    
rSize.SetHeight(rSh.GetAnyCurRect(CurRectType::FlyEmbedded).Height());
+                SwFormatFrameSize aSize(aSet.Get(RES_FRM_SIZE));
+                if (aSize.GetWidthPercent() && aSize.GetWidthPercent() != 
SwFormatFrameSize::SYNCED)
+                    
aSize.SetWidth(rSh.GetAnyCurRect(CurRectType::FlyEmbedded).Width());
+                if (aSize.GetHeightPercent() && aSize.GetHeightPercent() != 
SwFormatFrameSize::SYNCED)
+                    
aSize.SetHeight(rSh.GetAnyCurRect(CurRectType::FlyEmbedded).Height());
+                if (aSize != aSet.Get(RES_FRM_SIZE))
+                {
+                    aSet.Put(aSize);
+                }
 
                 // disable vertical positioning for Math Objects anchored 'as 
char' if baseline alignment is activated
                 aSet.Put( SfxBoolItem( FN_MATH_BASELINE_ALIGNMENT,

Reply via email to