Make sure projects are cleaned up nicely when frames close

PROJECT objects will be deleted by SETTINGS_MANAGER::UnloadProject
so we need to make sure that this is called at an early enough point
in the closing process that anything needed by the PROJECT dtor
is still around.

Also fix an issue where the schematic worksheet was depending on
the project existing after the schematic had been reset.
This commit is contained in:
Jon Evans 2020-08-08 16:52:57 -04:00
parent 79e40cf765
commit 32a7d00256
6 changed files with 26 additions and 0 deletions

View File

@ -120,6 +120,8 @@ void SCH_DRAW_PANEL::DisplaySheet( const SCH_SCREEN *aScreen )
if( aScreen ) if( aScreen )
GetView()->DisplaySheet( const_cast<SCH_SCREEN*>( aScreen ) ); GetView()->DisplaySheet( const_cast<SCH_SCREEN*>( aScreen ) );
else
GetView()->Cleanup();
} }

View File

@ -307,6 +307,10 @@ SCH_EDIT_FRAME::~SCH_EDIT_FRAME()
SetScreen( NULL ); SetScreen( NULL );
delete m_schematic; delete m_schematic;
// Close the project if we are standalone, so it gets cleaned up properly
if( Kiface().IsSingle() )
GetSettingsManager()->UnloadProject( &Prj() );
} }
@ -559,6 +563,9 @@ void SCH_EDIT_FRAME::OnCloseWindow( wxCloseEvent& aEvent )
// all sub sheets are deleted, only the main sheet is usable // all sub sheets are deleted, only the main sheet is usable
GetCurrentSheet().clear(); GetCurrentSheet().clear();
// Clear view before destroying schematic as repaints depend on schematic being valid
SetScreen( nullptr );
GetSettingsManager()->SaveProject(); GetSettingsManager()->SaveProject();
Schematic().SetTemplateFieldNames( nullptr ); Schematic().SetTemplateFieldNames( nullptr );
Schematic().Reset(); Schematic().Reset();

View File

@ -62,6 +62,13 @@ SCH_VIEW::~SCH_VIEW()
{ {
} }
void SCH_VIEW::Cleanup()
{
Clear();
m_worksheet.reset();
m_preview.reset();
}
void SCH_VIEW::SetScale( double aScale, VECTOR2D aAnchor ) void SCH_VIEW::SetScale( double aScale, VECTOR2D aAnchor )
{ {

View File

@ -77,6 +77,8 @@ public:
SCH_VIEW( bool aIsDynamic, SCH_BASE_FRAME* aFrame ); SCH_VIEW( bool aIsDynamic, SCH_BASE_FRAME* aFrame );
~SCH_VIEW(); ~SCH_VIEW();
void Cleanup();
void DisplaySheet( SCH_SHEET* aSheet ); void DisplaySheet( SCH_SHEET* aSheet );
void DisplaySheet( SCH_SCREEN* aScreen ); void DisplaySheet( SCH_SCREEN* aScreen );
void DisplayComponent( LIB_PART* aPart ); void DisplayComponent( LIB_PART* aPart );

View File

@ -328,6 +328,9 @@ void KICAD_MANAGER_FRAME::OnCloseWindow( wxCloseEvent& Event )
{ {
Event.SetCanVeto( true ); Event.SetCanVeto( true );
// Ensure the project is closed before destruction.
CloseProject( true );
m_leftWin->Show( false ); m_leftWin->Show( false );
Destroy(); Destroy();

View File

@ -22,6 +22,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
#include <kiface_i.h>
#include <pcb_base_edit_frame.h> #include <pcb_base_edit_frame.h>
#include <tool/tool_manager.h> #include <tool/tool_manager.h>
#include <pcb_layer_widget.h> #include <pcb_layer_widget.h>
@ -59,6 +60,10 @@ PCB_BASE_EDIT_FRAME::~PCB_BASE_EDIT_FRAME()
GFootprintList.WriteCacheToFile( &footprintInfoCache ); GFootprintList.WriteCacheToFile( &footprintInfoCache );
} }
// Close the project if we are standalone, so it gets cleaned up properly
if( Kiface().IsSingle() )
GetSettingsManager()->UnloadProject( &Prj() );
GetCanvas()->GetView()->Clear(); GetCanvas()->GetView()->Clear();
} }