diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_lib_plugin_cache.cpp b/eeschema/sch_plugins/kicad/sch_sexpr_lib_plugin_cache.cpp index a889c46caf..2d05893a01 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_lib_plugin_cache.cpp +++ b/eeschema/sch_plugins/kicad/sch_sexpr_lib_plugin_cache.cpp @@ -97,19 +97,23 @@ void SCH_SEXPR_PLUGIN_CACHE::Save( const std::optional& aOpt ) std::vector orderedSymbols; - for( const std::pair& parent : m_symbols ) - orderedSymbols.push_back( parent.second ); + for( const auto& [ name, symbol ] : m_symbols ) + { + if( symbol ) + orderedSymbols.push_back( symbol ); + } // Library must be ordered by inheritance depth. std::sort( orderedSymbols.begin(), orderedSymbols.end(), []( const LIB_SYMBOL* aLhs, const LIB_SYMBOL* aRhs ) { - wxCHECK( aLhs && aRhs, false ); + unsigned int lhDepth = aLhs->GetInheritanceDepth(); + unsigned int rhDepth = aRhs->GetInheritanceDepth(); - if( aLhs->GetInheritanceDepth() < aRhs->GetInheritanceDepth() ) - return true; + if( lhDepth == rhDepth ) + return aLhs->GetName() < aRhs->GetName(); - return aLhs->GetName() < aRhs->GetName(); + return lhDepth < rhDepth; } ); for( LIB_SYMBOL* symbol : orderedSymbols )