From 46701c11958081d951037996241a6827f5384dd6 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 8 Jul 2021 19:41:28 +0100 Subject: [PATCH] Don't allow undo record to get pushed during an undo. When doing a schematic cleanup, for instance, we were breaking wires and pushing undo records on to the stack. Needless to say, this was pretty unexpected for the rest of the undo framework and caused all kinds of mayhem (including crashes in some cases). Fixes https://gitlab.com/kicad/code/kicad/issues/8704 --- eeschema/tools/sch_editor_control.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/eeschema/tools/sch_editor_control.cpp b/eeschema/tools/sch_editor_control.cpp index c880785479..2e106e4ac3 100644 --- a/eeschema/tools/sch_editor_control.cpp +++ b/eeschema/tools/sch_editor_control.cpp @@ -1166,18 +1166,23 @@ int SCH_EDITOR_CONTROL::Undo( const TOOL_EVENT& aEvent ) /* Get the old list */ PICKED_ITEMS_LIST* List = m_frame->PopCommandFromUndoList(); + size_t num_undos = m_frame->m_undoList.m_CommandsList.size(); /* Undo the command */ m_frame->PutDataInPreviousState( List ); - /* Put the old list in RedoList */ - List->ReversePickersListOrder(); - m_frame->PushCommandToRedoList( List ); - m_frame->SetSheetNumberAndCount(); m_frame->TestDanglingEnds(); m_frame->OnPageSettingsChange(); + // If we modified anything during cleanup we don't want it going on the undolist + while( m_frame->m_undoList.m_CommandsList.size() > num_undos ) + delete m_frame->PopCommandFromUndoList(); + + // Now push the old command to the RedoList + List->ReversePickersListOrder(); + m_frame->PushCommandToRedoList( List ); + m_toolMgr->GetTool()->RebuildSelection(); m_frame->SyncView();