Set the screen pointer to null before deleting the associated items

VIEW needs to be cleared before deleting the stored items. Otherwise it
may dereference stale pointers leading to a crash.
This commit is contained in:
Maciej Suminski 2018-12-11 15:15:47 +01:00
parent 372a09f299
commit 7e1498a46f
1 changed files with 2 additions and 0 deletions

View File

@ -235,6 +235,7 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
// unload current project file before loading new // unload current project file before loading new
{ {
SetScreen( nullptr );
delete g_RootSheet; delete g_RootSheet;
g_RootSheet = NULL; g_RootSheet = NULL;
@ -283,6 +284,7 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
} }
else else
{ {
SetScreen( nullptr );
delete g_RootSheet; // Delete the current project. delete g_RootSheet; // Delete the current project.
g_RootSheet = NULL; // Force CreateScreens() to build new empty project on load failure. g_RootSheet = NULL; // Force CreateScreens() to build new empty project on load failure.
SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_LEGACY ) ); SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_LEGACY ) );