From 37d9b7fac0ae51554454eb1ab134066337ad94d5 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Sat, 25 Nov 2023 16:01:12 -0500 Subject: [PATCH] Prevent crash if generator exists but has no items See https://gitlab.com/kicad/code/kicad/-/issues/15366 --- pcbnew/tools/pcb_selection_tool.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/pcbnew/tools/pcb_selection_tool.cpp b/pcbnew/tools/pcb_selection_tool.cpp index 01dd38c596..a15fed90c8 100644 --- a/pcbnew/tools/pcb_selection_tool.cpp +++ b/pcbnew/tools/pcb_selection_tool.cpp @@ -2367,13 +2367,24 @@ bool PCB_SELECTION_TOOL::itemPassesFilter( BOARD_ITEM* aItem, bool aMultiSelect } } - if( aItem->Type() == PCB_GENERATOR_T ) - aItem = *( static_cast( aItem )->GetItems().begin() ); - if( !aItem ) return false; - switch( aItem->Type() ) + KICAD_T itemType = aItem->Type(); + + if( itemType == PCB_GENERATOR_T ) + { + if( static_cast( aItem )->GetItems().empty() ) + { + wxASSERT_MSG( false, "Tried to select an empty generator" ); + } + else + { + itemType = ( *static_cast( aItem )->GetItems().begin() )->Type(); + } + } + + switch( itemType ) { case PCB_FOOTPRINT_T: if( !m_filter.footprints )