Footprint chooser: fix crash when closing the dialog with a large footprint.

The crash was perhaps due to use after delete of data in DTOR functions, when
a footprint with a **lot** of graphics was loaded and the view cleared.
The view is now cleared before any other deletion.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/20915

(cherry picked from commit 63babb1a223da77af4c4c67b4fd30c6a3f60f0f1)
This commit is contained in:
jean-pierre charras 2025-05-13 16:10:56 +02:00
parent 0dde037ab9
commit 0bf415a266
3 changed files with 18 additions and 0 deletions

View File

@ -236,6 +236,9 @@ FOOTPRINT_CHOOSER_FRAME::~FOOTPRINT_CHOOSER_FRAME()
m_preview3DCanvas->Show();
m_preview3DCanvas->OnCloseWindow( dummy );
// Ensure view and data used by the preview panel are cleared before deleting other items
static_cast<FOOTPRINT_PREVIEW_PANEL*>( m_chooserPanel->GetViewerPanel()->GetPreviewPanel() )->ClearViewAndData();
// Disconnect board, which is owned by FOOTPRINT_PREVIEW_PANEL.
m_pcb = nullptr;

View File

@ -47,6 +47,7 @@
#include <dialog_shim.h>
#include <project_pcb.h>
FOOTPRINT_PREVIEW_PANEL::FOOTPRINT_PREVIEW_PANEL( KIWAY* aKiway, wxWindow* aParent,
UNITS_PROVIDER* aUnitsProvider,
std::unique_ptr<KIGFX::GAL_DISPLAY_OPTIONS> aOpts,
@ -75,6 +76,12 @@ FOOTPRINT_PREVIEW_PANEL::FOOTPRINT_PREVIEW_PANEL( KIWAY* aKiway, wxWindow* aPare
FOOTPRINT_PREVIEW_PANEL::~FOOTPRINT_PREVIEW_PANEL( )
{
ClearViewAndData();
}
void FOOTPRINT_PREVIEW_PANEL::ClearViewAndData()
{
m_dummyBoard->DetachAllFootprints();
@ -85,6 +92,9 @@ FOOTPRINT_PREVIEW_PANEL::~FOOTPRINT_PREVIEW_PANEL( )
GetView()->Remove( m_otherFootprint.get() );
GetView()->Clear();
m_currentFootprint = nullptr;
m_otherFootprint = nullptr;
}

View File

@ -76,6 +76,11 @@ public:
UNITS_PROVIDER* aUnitsProvider );
FOOTPRINT* GetCurrentFootprint() const { return m_currentFootprint.get(); }
/* Delete loaded footprints and clear view
* Must be called before deleting the panel
*/
void ClearViewAndData();
private:
/**
* Create a new panel