Shutdown safety. (Potentially KICAD-TJK.)

This commit is contained in:
Jeff Young 2025-07-08 14:23:58 +01:00
parent cef15bcf30
commit 479daa37c5
8 changed files with 42 additions and 9 deletions

View File

@ -290,6 +290,9 @@ void LIB_TREE::ShutdownPreviews()
if( m_previewWindow ) if( m_previewWindow )
{ {
// Shutdown the preview window's canvas
m_adapter->ShutdownPreview( m_previewWindow );
m_previewWindow->Hide(); m_previewWindow->Hide();
m_previewWindow->Destroy(); m_previewWindow->Destroy();
m_previewWindow = nullptr; m_previewWindow = nullptr;

View File

@ -55,7 +55,6 @@ public:
SCH_RENDER_SETTINGS* GetRenderSettings() const; SCH_RENDER_SETTINGS* GetRenderSettings() const;
protected: protected:
void onPaint( wxPaintEvent& WXUNUSED( aEvent ) ) override; void onPaint( wxPaintEvent& WXUNUSED( aEvent ) ) override;

View File

@ -381,11 +381,12 @@ bool SYMBOL_TREE_SYNCHRONIZING_ADAPTER::HasPreview( const wxDataViewItem& aItem
} }
static const wxString c_previewName = wxS( "symHoverPreview" );
void SYMBOL_TREE_SYNCHRONIZING_ADAPTER::ShowPreview( wxWindow* aParent, void SYMBOL_TREE_SYNCHRONIZING_ADAPTER::ShowPreview( wxWindow* aParent,
const wxDataViewItem& aItem ) const wxDataViewItem& aItem )
{ {
static const wxString c_previewName = wxS( "symHoverPreview" );
LIB_TREE_NODE* node = ToNode( aItem ); LIB_TREE_NODE* node = ToNode( aItem );
wxCHECK( node, /* void */ ); wxCHECK( node, /* void */ );
@ -416,3 +417,15 @@ void SYMBOL_TREE_SYNCHRONIZING_ADAPTER::ShowPreview( wxWindow* aPare
preview->DisplaySymbol( node->m_LibId, node->m_Unit ); preview->DisplaySymbol( node->m_LibId, node->m_Unit );
} }
void SYMBOL_TREE_SYNCHRONIZING_ADAPTER::ShutdownPreview( wxWindow* aParent )
{
wxWindow* previewWindow = wxWindow::FindWindowByName( c_previewName, aParent );
if( SYMBOL_PREVIEW_WIDGET* preview = dynamic_cast<SYMBOL_PREVIEW_WIDGET*>( previewWindow ) )
{
preview->GetCanvas()->SetEvtHandlerEnabled( false );
preview->GetCanvas()->StopDrawing();
}
}

View File

@ -50,8 +50,9 @@ public:
wxDataViewItem GetCurrentDataViewItem() override; wxDataViewItem GetCurrentDataViewItem() override;
virtual bool HasPreview( const wxDataViewItem& aItem ) override; bool HasPreview( const wxDataViewItem& aItem ) override;
virtual void ShowPreview( wxWindow* aParent, const wxDataViewItem& aItem ) override; void ShowPreview( wxWindow* aParent, const wxDataViewItem& aItem ) override;
void ShutdownPreview( wxWindow* aParent ) override;
protected: protected:
void updateLibrary( LIB_TREE_NODE_LIBRARY& aLibNode ); void updateLibrary( LIB_TREE_NODE_LIBRARY& aLibNode );

View File

@ -60,6 +60,8 @@ public:
void DisplayPart( LIB_SYMBOL* aSymbol, int aUnit, int aBodyStyle = 0 ); void DisplayPart( LIB_SYMBOL* aSymbol, int aUnit, int aBodyStyle = 0 );
EDA_DRAW_PANEL_GAL* GetCanvas() const { return m_preview; }
protected: protected:
void onSize( wxSizeEvent& aEvent ); void onSize( wxSizeEvent& aEvent );

View File

@ -265,6 +265,7 @@ public:
virtual bool HasPreview( const wxDataViewItem& aItem ) { return false; } virtual bool HasPreview( const wxDataViewItem& aItem ) { return false; }
virtual void ShowPreview( wxWindow* aParent, const wxDataViewItem& aItem ) {} virtual void ShowPreview( wxWindow* aParent, const wxDataViewItem& aItem ) {}
virtual void ShutdownPreview( wxWindow* aParent ) {}
TOOL_DISPATCHER* GetToolDispatcher() const { return m_parent->GetToolDispatcher(); } TOOL_DISPATCHER* GetToolDispatcher() const { return m_parent->GetToolDispatcher(); }

View File

@ -333,10 +333,11 @@ bool FP_TREE_SYNCHRONIZING_ADAPTER::HasPreview( const wxDataViewItem& aItem )
} }
void FP_TREE_SYNCHRONIZING_ADAPTER::ShowPreview( wxWindow* aParent, const wxDataViewItem& aItem )
{
static const wxString c_previewName = wxS( "fpHoverPreview" ); static const wxString c_previewName = wxS( "fpHoverPreview" );
void FP_TREE_SYNCHRONIZING_ADAPTER::ShowPreview( wxWindow* aParent, const wxDataViewItem& aItem )
{
LIB_TREE_NODE* node = ToNode( aItem ); LIB_TREE_NODE* node = ToNode( aItem );
wxCHECK( node, /* void */ ); wxCHECK( node, /* void */ );
@ -359,3 +360,15 @@ void FP_TREE_SYNCHRONIZING_ADAPTER::ShowPreview( wxWindow* aParent, const wxData
preview->DisplayFootprint( node->m_LibId ); preview->DisplayFootprint( node->m_LibId );
} }
void FP_TREE_SYNCHRONIZING_ADAPTER::ShutdownPreview( wxWindow* aParent )
{
wxWindow* previewWindow = wxWindow::FindWindowByName( c_previewName, aParent );
if( FOOTPRINT_PREVIEW_PANEL* preview = dynamic_cast<FOOTPRINT_PREVIEW_PANEL*>( previewWindow ) )
{
preview->GetCanvas()->SetEvtHandlerEnabled( false );
preview->GetCanvas()->StopDrawing();
}
}

View File

@ -46,8 +46,9 @@ public:
wxDataViewItem GetCurrentDataViewItem() override; wxDataViewItem GetCurrentDataViewItem() override;
virtual bool HasPreview( const wxDataViewItem& aItem ) override; bool HasPreview( const wxDataViewItem& aItem ) override;
virtual void ShowPreview( wxWindow* aParent, const wxDataViewItem& aItem ) override; void ShowPreview( wxWindow* aParent, const wxDataViewItem& aItem ) override;
void ShutdownPreview( wxWindow* aParent ) override;
protected: protected:
FP_TREE_SYNCHRONIZING_ADAPTER( FOOTPRINT_EDIT_FRAME* aFrame, FP_LIB_TABLE* aLibs ); FP_TREE_SYNCHRONIZING_ADAPTER( FOOTPRINT_EDIT_FRAME* aFrame, FP_LIB_TABLE* aLibs );