From 47d86e5d9e5b0b195a076ee320acd1a74a95e8fe Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Wed, 23 Nov 2022 16:20:12 -0800 Subject: [PATCH] Don't crash when canceling graphics import Grouped graphics need to have their group removed from the preview before deleting the elements to avoid reading freed memory when redrawing --- pcbnew/tools/drawing_tool.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index 011f008c59..dd9b4ac9d8 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -1602,6 +1602,12 @@ int DRAWING_TOOL::PlaceImportedGraphics( const TOOL_EVENT& aEvent ) { m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); + if( group ) + { + preview.Remove( group ); + group->RemoveAll(); + } + for( BOARD_ITEM* item : newItems ) delete item;