From 0df8d5c2d69107897f574b43178c23a34c3dcd80 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Thu, 11 Jan 2024 15:41:58 -0500 Subject: [PATCH] Do not assert when pruning orphaned sheet and/or symbol instances. Running the schematic editor in the stand alone mode can result in an empty project name. Rather than assert when the project name is empty, just don't run the pruning algorithm. The pruning will just have to happen on the next load of the schematic when it has a proper project name. Fixes https://gitlab.com/kicad/code/kicad/-/issues/16577 --- eeschema/sch_screen.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp index 119940218e..55895c114b 100644 --- a/eeschema/sch_screen.cpp +++ b/eeschema/sch_screen.cpp @@ -4,7 +4,7 @@ * Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck * Copyright (C) 2008 Wayne Stambaugh - * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2024 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -1645,8 +1645,10 @@ void SCH_SCREEN::PruneOrphanedSymbolInstances( const wxString& aProjectName, // The project name cannot be empty. Projects older than 7.0 did not save project names // when saving instance data. Running this algorithm with an empty project name would // clobber all instance data for projects other than the current one when a schematic - // file is shared across multiple projects. - wxCHECK( !aProjectName.IsEmpty(), /* void */ ); + // file is shared across multiple projects. Because running the schematic editor in + // stand alone mode can result in an empty project name, do not assert here. + if( aProjectName.IsEmpty() ) + return; for( SCH_ITEM* item : Items().OfType( SCH_SYMBOL_T ) ) { @@ -1690,8 +1692,10 @@ void SCH_SCREEN::PruneOrphanedSheetInstances( const wxString& aProjectName, // The project name cannot be empty. Projects older than 7.0 did not save project names // when saving instance data. Running this algorithm with an empty project name would // clobber all instance data for projects other than the current one when a schematic - // file is shared across multiple projects. - wxCHECK( !aProjectName.IsEmpty(), /* void */ ); + // file is shared across multiple projects. Because running the schematic editor in + // stand alone mode can result in an empty project name, do not assert here. + if( aProjectName.IsEmpty() ) + return; for( SCH_ITEM* item : Items().OfType( SCH_SHEET_T ) ) { @@ -2157,7 +2161,8 @@ void SCH_SCREEN::MigrateSimModels() void SCH_SCREENS::PruneOrphanedSymbolInstances( const wxString& aProjectName, const SCH_SHEET_LIST& aValidSheetPaths ) { - wxCHECK( !aProjectName.IsEmpty(), /* void */ ); + if( aProjectName.IsEmpty() ) + return; for( SCH_SCREEN* screen = GetFirst(); screen; screen = GetNext() ) screen->PruneOrphanedSymbolInstances( aProjectName, aValidSheetPaths ); @@ -2167,7 +2172,8 @@ void SCH_SCREENS::PruneOrphanedSymbolInstances( const wxString& aProjectName, void SCH_SCREENS::PruneOrphanedSheetInstances( const wxString& aProjectName, const SCH_SHEET_LIST& aValidSheetPaths ) { - wxCHECK( !aProjectName.IsEmpty(), /* void */ ); + if( aProjectName.IsEmpty() ) + return; for( SCH_SCREEN* screen = GetFirst(); screen; screen = GetNext() ) screen->PruneOrphanedSheetInstances( aProjectName, aValidSheetPaths );