Prevent holding dangling pointers when rebuilding
Changing properties consecutively can rebuild the grid, leading to
dangling pointers. Storing references by name keeps the current pointer
accurate
Fixes https://gitlab.com/kicad/code/kicad/-/issues/22262
(cherry picked from commit 458db88648)
This commit is contained in:
@@ -311,13 +311,21 @@ wxPGWindowList PG_COLOR_EDITOR::CreateControls( wxPropertyGrid* aGrid, wxPGPrope
|
||||
editor->SetPosition( aPos );
|
||||
editor->SetSize( aSize );
|
||||
|
||||
// Capture property name instead of pointer to avoid dangling pointer if grid is rebuilt
|
||||
wxString propName = colorProp->GetName();
|
||||
|
||||
editor->Bind( COLOR_SWATCH_CHANGED,
|
||||
[=]( wxCommandEvent& aEvt )
|
||||
{
|
||||
wxVariant val;
|
||||
auto data = new COLOR4D_VARIANT_DATA( editor->GetSwatchColor() );
|
||||
val.SetData( data );
|
||||
aGrid->ChangePropertyValue( colorProp, val );
|
||||
wxPGProperty* prop = aGrid->GetPropertyByName( propName );
|
||||
|
||||
if( prop )
|
||||
{
|
||||
wxVariant val;
|
||||
auto data = new COLOR4D_VARIANT_DATA( editor->GetSwatchColor() );
|
||||
val.SetData( data );
|
||||
aGrid->ChangePropertyValue( prop, val );
|
||||
}
|
||||
} );
|
||||
|
||||
#if wxCHECK_VERSION( 3, 3, 0 )
|
||||
@@ -330,6 +338,11 @@ wxPGWindowList PG_COLOR_EDITOR::CreateControls( wxPropertyGrid* aGrid, wxPGPrope
|
||||
[=]()
|
||||
{
|
||||
editor->GetNewSwatchColor();
|
||||
|
||||
wxPGProperty* prop = aGrid->GetPropertyByName( propName );
|
||||
|
||||
if( prop )
|
||||
aGrid->DrawItem( prop );
|
||||
} );
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user