From b44dbc90fe2053c675b5505f74c9e591058ee40a Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Fri, 9 Oct 2020 19:39:03 +0100 Subject: [PATCH] pleditor: Don't double delete items being placed The RollbackFromUndo function deletes the items, so they shouldn't be deleted before it is called. --- pagelayout_editor/tools/pl_drawing_tools.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/pagelayout_editor/tools/pl_drawing_tools.cpp b/pagelayout_editor/tools/pl_drawing_tools.cpp index 9fd7bbde85..45a80274fc 100644 --- a/pagelayout_editor/tools/pl_drawing_tools.cpp +++ b/pagelayout_editor/tools/pl_drawing_tools.cpp @@ -108,14 +108,16 @@ int PL_DRAWING_TOOLS::PlaceItem( const TOOL_EVENT& aEvent ) cursorPos = getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) ); - auto cleanup = [&] () { - m_toolMgr->RunAction( PL_ACTIONS::clearSelection, true ); - delete item; - item = nullptr; + auto cleanup = + [&] () + { + m_toolMgr->RunAction( PL_ACTIONS::clearSelection, true ); + item = nullptr; - // There's nothing to roll-back, but we still need to pop the undo stack - m_frame->RollbackFromUndo(); - }; + // There's nothing to roll-back, but we still need to pop the undo stack + // This also deletes the item being placed. + m_frame->RollbackFromUndo(); + }; if( evt->IsCancelInteractive() ) { @@ -246,6 +248,8 @@ int PL_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent ) if( item ) { item = nullptr; + + // Pop the undo stack and delete the item being placed m_frame->RollbackFromUndo(); } else if( evt->IsCancelInteractive() )