From 32a7d00256aac52477427b7ddd786a79fa2d034f Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Sat, 8 Aug 2020 16:52:57 -0400 Subject: [PATCH] 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. --- eeschema/sch_draw_panel.cpp | 2 ++ eeschema/sch_edit_frame.cpp | 7 +++++++ eeschema/sch_view.cpp | 7 +++++++ eeschema/sch_view.h | 2 ++ kicad/kicad_manager_frame.cpp | 3 +++ pcbnew/pcb_base_edit_frame.cpp | 5 +++++ 6 files changed, 26 insertions(+) diff --git a/eeschema/sch_draw_panel.cpp b/eeschema/sch_draw_panel.cpp index 5991d1278f..a607cc98fc 100644 --- a/eeschema/sch_draw_panel.cpp +++ b/eeschema/sch_draw_panel.cpp @@ -120,6 +120,8 @@ void SCH_DRAW_PANEL::DisplaySheet( const SCH_SCREEN *aScreen ) if( aScreen ) GetView()->DisplaySheet( const_cast( aScreen ) ); + else + GetView()->Cleanup(); } diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index 393fc4f198..9679457986 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -307,6 +307,10 @@ SCH_EDIT_FRAME::~SCH_EDIT_FRAME() SetScreen( NULL ); 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 GetCurrentSheet().clear(); + // Clear view before destroying schematic as repaints depend on schematic being valid + SetScreen( nullptr ); + GetSettingsManager()->SaveProject(); Schematic().SetTemplateFieldNames( nullptr ); Schematic().Reset(); diff --git a/eeschema/sch_view.cpp b/eeschema/sch_view.cpp index ff3bd8f830..5057c80d47 100644 --- a/eeschema/sch_view.cpp +++ b/eeschema/sch_view.cpp @@ -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 ) { diff --git a/eeschema/sch_view.h b/eeschema/sch_view.h index a60e908254..520f5c3672 100644 --- a/eeschema/sch_view.h +++ b/eeschema/sch_view.h @@ -77,6 +77,8 @@ public: SCH_VIEW( bool aIsDynamic, SCH_BASE_FRAME* aFrame ); ~SCH_VIEW(); + void Cleanup(); + void DisplaySheet( SCH_SHEET* aSheet ); void DisplaySheet( SCH_SCREEN* aScreen ); void DisplayComponent( LIB_PART* aPart ); diff --git a/kicad/kicad_manager_frame.cpp b/kicad/kicad_manager_frame.cpp index 73f67749dd..7711826b59 100644 --- a/kicad/kicad_manager_frame.cpp +++ b/kicad/kicad_manager_frame.cpp @@ -328,6 +328,9 @@ void KICAD_MANAGER_FRAME::OnCloseWindow( wxCloseEvent& Event ) { Event.SetCanVeto( true ); + // Ensure the project is closed before destruction. + CloseProject( true ); + m_leftWin->Show( false ); Destroy(); diff --git a/pcbnew/pcb_base_edit_frame.cpp b/pcbnew/pcb_base_edit_frame.cpp index cd8a9621f2..01ba1bf3ba 100644 --- a/pcbnew/pcb_base_edit_frame.cpp +++ b/pcbnew/pcb_base_edit_frame.cpp @@ -22,6 +22,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ +#include #include #include #include @@ -59,6 +60,10 @@ PCB_BASE_EDIT_FRAME::~PCB_BASE_EDIT_FRAME() 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(); }