design blocks: don't crash on missing preview widget

Copied from footprint preview widget, which has the same issue
This commit is contained in:
Mike Williams
2026-03-18 09:47:40 -04:00
parent 7c06e9ba12
commit 08349b8d8a
4 changed files with 20 additions and 0 deletions
@@ -45,6 +45,11 @@ public:
DESIGN_BLOCK_PREVIEW_WIDGET( wxWindow* aParent ) : wxPanel( aParent ) {}
~DESIGN_BLOCK_PREVIEW_WIDGET() = default;
/**
* Return whether the widget initialized properly. This could return false if Kiway is
* not available. If this returns false, no other methods should be called.
*/
virtual bool IsInitialized() const = 0;
/**
* Set the contents of the status label and display it.
@@ -318,6 +318,9 @@ void PANEL_DESIGN_BLOCK_CHOOSER::onOpenLibsTimer( wxTimerEvent& aEvent )
void PANEL_DESIGN_BLOCK_CHOOSER::onDesignBlockSelected( wxCommandEvent& aEvent )
{
if( !m_preview || !m_preview->IsInitialized() )
return;
if( GetSelectedLibId().IsValid() )
{
std::unique_ptr<DESIGN_BLOCK> designBlock( m_parent->GetDesignBlock( GetSelectedLibId(), true, true ) );
@@ -47,6 +47,12 @@ public:
~SCH_DESIGN_BLOCK_PREVIEW_WIDGET() override;
/*
* Return whether the widget initialized properly. This could return false if Kiway is
* not available. If this returns false, no other methods should be called.
*/
bool IsInitialized() const override { return m_preview != nullptr; }
/**
* Set the contents of the status label and display it.
*/
@@ -47,6 +47,12 @@ public:
~PCB_DESIGN_BLOCK_PREVIEW_WIDGET() override;
/**
* Return whether the widget initialized properly. This could return false if Kiway is
* not available. If this returns false, no other methods should be called.
*/
bool IsInitialized() const override { return m_preview != nullptr; }
/**
* Set the contents of the status label and display it.
*/