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

New commits:
commit 68842700990c0147ccb8376021663161e8c6bc03
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Tue Jul 29 08:47:32 2025 +0200
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Tue Jul 29 10:10:52 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/+/188522
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/sw/source/uibase/shells/frmsh.cxx 
b/sw/source/uibase/shells/frmsh.cxx
index cca0595bdac5..775551cfd9f6 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