From 28075e6efedb15f944f64d79eec9ddd178ea961e Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 12 Jun 2023 23:07:04 +0100 Subject: [PATCH] Don't crash on empty selection in search list. Fixes https://gitlab.com/kicad/code/kicad/-/issues/14931 --- eeschema/widgets/search_handlers.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/eeschema/widgets/search_handlers.cpp b/eeschema/widgets/search_handlers.cpp index 258a25f2ef..5b94fcf282 100644 --- a/eeschema/widgets/search_handlers.cpp +++ b/eeschema/widgets/search_handlers.cpp @@ -76,6 +76,8 @@ void SCH_SEARCH_HANDLER::SelectItems( std::vector& aItemRows ) EDA_ITEMS selectedItems; std::vector selectedHits; + m_frame->GetToolManager()->RunAction( EE_ACTIONS::clearSelection, true ); + for( long row : aItemRows ) { if( row >= 0 && row < (long) m_hitlist.size() ) @@ -85,14 +87,15 @@ void SCH_SEARCH_HANDLER::SelectItems( std::vector& aItemRows ) } } + if( selectedHits.empty() ) + return; + bool allHitsOnSamePage = std::all_of( selectedHits.begin() + 1, selectedHits.end(), [&]( const SCH_SEARCH_HIT& r ) { return r.sheetPath == selectedHits.front().sheetPath; } ); - m_frame->GetToolManager()->RunAction( EE_ACTIONS::clearSelection, true ); - if( allHitsOnSamePage && !selectedHits.empty() ) { m_frame->SetCurrentSheet( *selectedHits.front().sheetPath );