diff --git a/eeschema/sch_legacy_plugin.cpp b/eeschema/sch_legacy_plugin.cpp index cef7e31bbe..573530c5a3 100644 --- a/eeschema/sch_legacy_plugin.cpp +++ b/eeschema/sch_legacy_plugin.cpp @@ -693,21 +693,6 @@ void SCH_LEGACY_PLUGIN::loadHierarchy( SCH_SHEET* aSheet ) try { loadFile( fileName.GetFullPath(), aSheet->GetScreen() ); - for( auto aItem : aSheet->GetScreen()->Items().OfType( SCH_SHEET_T ) ) - { - assert( aItem->Type() == SCH_SHEET_T ); - auto sheet = static_cast( aItem ); - - // Set the parent to aSheet. This effectively creates a method to find - // the root sheet from any sheet so a pointer to the root sheet does not - // need to be stored globally. Note: this is not the same as a hierarchy. - // Complex hierarchies can have multiple copies of a sheet. This only - // provides a simple tree to find the root sheet. - sheet->SetParent( aSheet ); - - // Recursion starts here. - loadHierarchy( sheet ); - } } catch( const IO_ERROR& ioe ) { @@ -721,6 +706,22 @@ void SCH_LEGACY_PLUGIN::loadHierarchy( SCH_SHEET* aSheet ) m_error += ioe.What(); } + + for( auto aItem : aSheet->GetScreen()->Items().OfType( SCH_SHEET_T ) ) + { + wxCHECK2( aItem->Type() == SCH_SHEET_T, continue ); + auto sheet = static_cast( aItem ); + + // Set the parent to aSheet. This effectively creates a method to find + // the root sheet from any sheet so a pointer to the root sheet does not + // need to be stored globally. Note: this is not the same as a hierarchy. + // Complex hierarchies can have multiple copies of a sheet. This only + // provides a simple tree to find the root sheet. + sheet->SetParent( aSheet ); + + // Recursion starts here. + loadHierarchy( sheet ); + } } m_currentPath.pop();