Browse Source

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
pull/18/head
jean-pierre charras 5 months ago
parent
commit
63babb1a22
  1. 3
      pcbnew/footprint_chooser_frame.cpp
  2. 10
      pcbnew/footprint_preview_panel.cpp
  3. 5
      pcbnew/footprint_preview_panel.h

3
pcbnew/footprint_chooser_frame.cpp

@ -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;

10
pcbnew/footprint_preview_panel.cpp

@ -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;
}

5
pcbnew/footprint_preview_panel.h

@ -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

Loading…
Cancel
Save