tdf#126168: sw undo/redo crash fixed

After undo of style creation we have a dangling pointers to
deleted style in SwUndoSetFlyFormat. So instead of keeping
pointers to SwFrameFormat which can be invalidated, we could
keep style name and find style by name.

Change-Id: I9a60d6b3311278d7391d676010c31c862189fd08
Reviewed-on: https://gerrit.libreoffice.org/76351
Reviewed-by: Michael Stahl <Michael.Stahl@cib.de>
Tested-by: Jenkins
This commit is contained in:
Vasily Melenchuk
2019-07-26 10:45:59 +03:00
committed by Thorsten Behrens
parent 892b434f92
commit 20e7632919
2 changed files with 13 additions and 12 deletions

View File

@@ -188,8 +188,8 @@ public:
class SwUndoSetFlyFormat : public SwUndo, public SwClient class SwUndoSetFlyFormat : public SwUndo, public SwClient
{ {
SwFrameFormat* m_pFrameFormat; // saved FlyFormat SwFrameFormat* m_pFrameFormat; // saved FlyFormat
SwFrameFormat* const m_pOldFormat; const OUString m_DerivedFromFormatName;
SwFrameFormat* m_pNewFormat; const OUString m_NewFormatName;
std::unique_ptr<SfxItemSet> m_pItemSet; // the re-/ set attributes std::unique_ptr<SfxItemSet> m_pItemSet; // the re-/ set attributes
sal_uLong m_nOldNode, m_nNewNode; sal_uLong m_nOldNode, m_nNewNode;
sal_Int32 m_nOldContent, m_nNewContent; sal_Int32 m_nOldContent, m_nNewContent;

View File

@@ -457,7 +457,8 @@ void SwUndoDelLayFormat::RedoForRollback()
SwUndoSetFlyFormat::SwUndoSetFlyFormat( SwFrameFormat& rFlyFormat, SwFrameFormat& rNewFrameFormat ) SwUndoSetFlyFormat::SwUndoSetFlyFormat( SwFrameFormat& rFlyFormat, SwFrameFormat& rNewFrameFormat )
: SwUndo( SwUndoId::SETFLYFRMFMT, rFlyFormat.GetDoc() ), SwClient( &rFlyFormat ), m_pFrameFormat( &rFlyFormat ), : SwUndo( SwUndoId::SETFLYFRMFMT, rFlyFormat.GetDoc() ), SwClient( &rFlyFormat ), m_pFrameFormat( &rFlyFormat ),
m_pOldFormat( static_cast<SwFrameFormat*>(rFlyFormat.DerivedFrom()) ), m_pNewFormat( &rNewFrameFormat ), m_DerivedFromFormatName( rFlyFormat.IsDefault() ? "" : rFlyFormat.DerivedFrom()->GetName() ),
m_NewFormatName( rNewFrameFormat.GetName() ),
m_pItemSet( new SfxItemSet( *rFlyFormat.GetAttrSet().GetPool(), m_pItemSet( new SfxItemSet( *rFlyFormat.GetAttrSet().GetPool(),
rFlyFormat.GetAttrSet().GetRanges() )), rFlyFormat.GetAttrSet().GetRanges() )),
m_nOldNode( 0 ), m_nNewNode( 0 ), m_nOldNode( 0 ), m_nNewNode( 0 ),
@@ -470,8 +471,7 @@ SwRewriter SwUndoSetFlyFormat::GetRewriter() const
{ {
SwRewriter aRewriter; SwRewriter aRewriter;
if (m_pNewFormat) aRewriter.AddRule(UndoArg1, m_NewFormatName);
aRewriter.AddRule(UndoArg1, m_pNewFormat->GetName());
return aRewriter; return aRewriter;
} }
@@ -532,13 +532,14 @@ void SwUndoSetFlyFormat::UndoImpl(::sw::UndoRedoContext & rContext)
SwDoc & rDoc = rContext.GetDoc(); SwDoc & rDoc = rContext.GetDoc();
// Is the new Format still existent? // Is the new Format still existent?
if (rDoc.GetFrameFormats()->IsAlive(m_pOldFormat)) SwFrameFormat* pDerivedFromFrameFormat = rDoc.FindFrameFormatByName(m_DerivedFromFormatName);
if (pDerivedFromFrameFormat)
{ {
if( m_bAnchorChanged ) if( m_bAnchorChanged )
m_pFrameFormat->DelFrames(); m_pFrameFormat->DelFrames();
if( m_pFrameFormat->DerivedFrom() != m_pOldFormat ) if( m_pFrameFormat->DerivedFrom() != pDerivedFromFrameFormat)
m_pFrameFormat->SetDerivedFrom( m_pOldFormat ); m_pFrameFormat->SetDerivedFrom(pDerivedFromFrameFormat);
SfxItemIter aIter( *m_pItemSet ); SfxItemIter aIter( *m_pItemSet );
const SfxPoolItem* pItem = aIter.GetCurItem(); const SfxPoolItem* pItem = aIter.GetCurItem();
@@ -606,19 +607,19 @@ void SwUndoSetFlyFormat::RedoImpl(::sw::UndoRedoContext & rContext)
SwDoc & rDoc = rContext.GetDoc(); SwDoc & rDoc = rContext.GetDoc();
// Is the new Format still existent? // Is the new Format still existent?
if (rDoc.GetFrameFormats()->IsAlive(m_pNewFormat)) SwFrameFormat* pNewFrameFormat = rDoc.FindFrameFormatByName(m_NewFormatName);
if (pNewFrameFormat)
{ {
if( m_bAnchorChanged ) if( m_bAnchorChanged )
{ {
SwFormatAnchor aNewAnchor( m_nNewAnchorType ); SwFormatAnchor aNewAnchor( m_nNewAnchorType );
GetAnchor( aNewAnchor, m_nNewNode, m_nNewContent ); GetAnchor( aNewAnchor, m_nNewNode, m_nNewContent );
SfxItemSet aSet( rDoc.GetAttrPool(), aFrameFormatSetRange ); SfxItemSet aSet( rDoc.GetAttrPool(), aFrameFormatSetRange );
aSet.Put( aNewAnchor ); aSet.Put( aNewAnchor );
rDoc.SetFrameFormatToFly( *m_pFrameFormat, *m_pNewFormat, &aSet ); rDoc.SetFrameFormatToFly( *m_pFrameFormat, *pNewFrameFormat, &aSet );
} }
else else
rDoc.SetFrameFormatToFly( *m_pFrameFormat, *m_pNewFormat ); rDoc.SetFrameFormatToFly( *m_pFrameFormat, *pNewFrameFormat);
rContext.SetSelections(m_pFrameFormat, nullptr); rContext.SetSelections(m_pFrameFormat, nullptr);
} }