diff --git a/eeschema/sch_sheet_path.cpp b/eeschema/sch_sheet_path.cpp index 2be088f7bd..2c7c290412 100644 --- a/eeschema/sch_sheet_path.cpp +++ b/eeschema/sch_sheet_path.cpp @@ -455,6 +455,8 @@ void SCH_SHEET_LIST::BuildSheetList( SCH_SHEET* aSheet ) { wxCHECK_RET( aSheet != NULL, wxT( "Cannot build sheet list from undefined sheet." ) ); + std::vector badSheets; + if( aSheet == g_RootSheet ) m_isRootSheet = true; @@ -477,11 +479,23 @@ void SCH_SHEET_LIST::BuildSheetList( SCH_SHEET* aSheet ) if( item->Type() == SCH_SHEET_T ) { SCH_SHEET* sheet = (SCH_SHEET*) item; - BuildSheetList( sheet ); + + if( !m_currentSheetPath.TestForRecursion( + sheet->GetFileName(), aSheet->GetFileName() ) ) + BuildSheetList( sheet ); + else + badSheets.push_back( sheet ); } item = item->Next(); } + + + for( auto sheet : badSheets ) + { + aSheet->GetScreen()->Remove( sheet ); + aSheet->GetScreen()->SetModify(); + } } m_currentSheetPath.pop_back();