diff --git a/pcbnew/board_connected_item.cpp b/pcbnew/board_connected_item.cpp index fe504a982c..de54479ea0 100644 --- a/pcbnew/board_connected_item.cpp +++ b/pcbnew/board_connected_item.cpp @@ -125,10 +125,20 @@ int BOARD_CONNECTED_ITEM::GetNetCode() const // std::shared_ptr stuff shows up large in performance profiling. NETCLASS* BOARD_CONNECTED_ITEM::GetEffectiveNetClass() const { + // Static fallback netclass for items without a valid board (e.g., during DRC evaluation + // of dummy items, or items not yet added to a board). + static std::shared_ptr fallbackNetclass = std::make_shared( NETCLASS::Default ); + if( m_netinfo && m_netinfo->GetNetClass() ) return m_netinfo->GetNetClass(); - else - return GetBoard()->GetDesignSettings().m_NetSettings->GetDefaultNetclass().get(); + + if( const BOARD* board = GetBoard() ) + { + if( board->GetDesignSettings().m_NetSettings ) + return board->GetDesignSettings().m_NetSettings->GetDefaultNetclass().get(); + } + + return fallbackNetclass.get(); } diff --git a/pcbnew/pcbexpr_functions.cpp b/pcbnew/pcbexpr_functions.cpp index d6033e3c65..6a982a21cb 100644 --- a/pcbnew/pcbexpr_functions.cpp +++ b/pcbnew/pcbexpr_functions.cpp @@ -1314,7 +1314,7 @@ static void hasNetclassFunc( LIBEVAL::CONTEXT* aCtx, void* self ) BOARD_CONNECTED_ITEM* bcItem = static_cast( item ); NETCLASS* netclass = bcItem->GetEffectiveNetClass(); - if( netclass->ContainsNetclassWithName( arg->AsString() ) ) + if( netclass && netclass->ContainsNetclassWithName( arg->AsString() ) ) return 1.0; return 0.0; @@ -1353,7 +1353,7 @@ static void hasExactNetclassFunc( LIBEVAL::CONTEXT* aCtx, void* self ) BOARD_CONNECTED_ITEM* bcItem = static_cast( item ); NETCLASS* netclass = bcItem->GetEffectiveNetClass(); - if( netclass->GetName() == arg->AsString() ) + if( netclass && netclass->GetName() == arg->AsString() ) return 1.0; return 0.0;