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
This commit is contained in:
Wayne Stambaugh 2024-01-11 15:41:58 -05:00
parent 382fe3de09
commit 0df8d5c2d6
1 changed files with 13 additions and 7 deletions

View File

@ -4,7 +4,7 @@
* Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
* 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 );