From 7be05e9eb1aafd7bbf87a2b4f2e1df2f192e708b Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 1 Oct 2022 13:49:53 +0100 Subject: [PATCH] Make sure we have nets before grabbing the first. Fixes https://gitlab.com/kicad/code/kicad/issues/12554 --- pcbnew/router/router_tool.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/pcbnew/router/router_tool.cpp b/pcbnew/router/router_tool.cpp index bf03caf65b..0262629f85 100644 --- a/pcbnew/router/router_tool.cpp +++ b/pcbnew/router/router_tool.cpp @@ -466,17 +466,18 @@ bool ROUTER_TOOL::Init() return !m_router->RoutingInProgress(); }; - auto hasOtherEnd = [&]( const SELECTION& ) - { - // Need to have something unconnected to finish to - return getEditFrame() - ->GetBoard() - ->GetConnectivity() - ->GetRatsnestForNet( m_router->GetCurrentNets()[0] ) - ->GetEdges() - .size() - > 0; - }; + auto hasOtherEnd = + [&]( const SELECTION& ) + { + std::vector currentNets = m_router->GetCurrentNets(); + + // Need to have something unconnected to finish to + int currentNet = currentNets.empty() ? -1 : currentNets[0]; + BOARD* board = getEditFrame()->GetBoard(); + RN_NET* ratsnest = board->GetConnectivity()->GetRatsnestForNet( currentNet ); + + return ratsnest && !ratsnest->GetEdges().empty(); + }; menu.AddItem( ACTIONS::cancelInteractive, SELECTION_CONDITIONS::ShowAlways, 1 ); menu.AddSeparator( 1 );