From df223cced4c53f54c428f640e74ce3597dd99929 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sat, 22 Oct 2022 18:30:30 +0200 Subject: [PATCH] pl_editor: fix a crash when trying to delete an item during its creation. Fixes #12717 https://gitlab.com/kicad/code/kicad/issues/12717 --- pagelayout_editor/tools/pl_edit_tool.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pagelayout_editor/tools/pl_edit_tool.cpp b/pagelayout_editor/tools/pl_edit_tool.cpp index 7b8fd20a33..787eceea53 100644 --- a/pagelayout_editor/tools/pl_edit_tool.cpp +++ b/pagelayout_editor/tools/pl_edit_tool.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2019 CERN - * Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2019-2022 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -357,6 +357,14 @@ int PL_EDIT_TOOL::DoDelete( const TOOL_EVENT& aEvent ) if( selection.Size() == 0 ) return 0; + + // Do not delete an item if it is currently a new item being created to avoid a crash + // In this case the selection contains only one item. + DS_DRAW_ITEM_BASE* currItem = static_cast( selection.Front() ); + + if( currItem->GetFlags() & ( IS_NEW ) ) + return 0; + m_frame->SaveCopyInUndoList(); while( selection.Front() )