From 790aa18f4137d78116dd2cccbe77b301f5c9b40f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 30 Oct 2024 16:12:14 +0100 Subject: [PATCH 1/3] Fix crash in wxPropertyGrid with wxGTK3 after recent change Since the recent 27fe76fcbf (Fix wxPropGrid editor appearance after DPI change, 2024-10-20) creating wxPropertyGrid in wxGTK immediately crashed if there was no selection in it. Check that we have a non-null selected property before calling RefreshProperty() with it to avoid this. See #24898. --- src/propgrid/propgrid.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/propgrid/propgrid.cpp b/src/propgrid/propgrid.cpp index b92a6c0bef..fb5b74dada 100644 --- a/src/propgrid/propgrid.cpp +++ b/src/propgrid/propgrid.cpp @@ -1378,7 +1378,8 @@ void wxPropertyGrid::OnDPIChanged(wxDPIChangedEvent &event) CalculateFontAndBitmapStuff(m_vspacing); Refresh(); - RefreshProperty(GetSelection()); + if ( wxPGProperty* const selected = GetSelection() ) + RefreshProperty(selected); event.Skip(); } From 76cb9b6ba163a653646e8f24c632cc4e33283f31 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 30 Oct 2024 16:15:18 +0100 Subject: [PATCH 2/3] Add parameter validity check to wxPropertyGrid::RefreshProperty() Don't crash in this function if it ever happens to be passed a null pointer again (see the fix in the parent commit) and document that it takes a non-null pointer. --- interface/wx/propgrid/propgrid.h | 2 ++ src/propgrid/propgrid.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/interface/wx/propgrid/propgrid.h b/interface/wx/propgrid/propgrid.h index 3993ada9b2..7085108d01 100644 --- a/interface/wx/propgrid/propgrid.h +++ b/interface/wx/propgrid/propgrid.h @@ -926,6 +926,8 @@ public: /** Redraws given property. + + @param p Valid, i.e. non-@NULL, property pointer. */ virtual void RefreshProperty( wxPGProperty* p ); diff --git a/src/propgrid/propgrid.cpp b/src/propgrid/propgrid.cpp index fb5b74dada..149c01bd35 100644 --- a/src/propgrid/propgrid.cpp +++ b/src/propgrid/propgrid.cpp @@ -2568,6 +2568,8 @@ void wxPropertyGrid::DrawItems( const wxPGProperty* p1, const wxPGProperty* p2 ) void wxPropertyGrid::RefreshProperty( wxPGProperty* p ) { + wxCHECK_RET( p, wxS("invalid property id") ); + if ( m_pState->DoIsPropertySelected(p) || p->IsChildSelected(true) ) { // NB: We must copy the selection. From c28eb2b1c757119bbd9dceb162371b127d6a18ed Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 30 Oct 2024 16:16:44 +0100 Subject: [PATCH 3/3] Also add the check to wxPropertyGrid::DrawItemAndValueRelated() This is similar to the previous commit and adds a check for the parameter being non-null to this function too for consistency and extra safety. --- interface/wx/propgrid/propgrid.h | 2 ++ src/propgrid/propgrid.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/interface/wx/propgrid/propgrid.h b/interface/wx/propgrid/propgrid.h index 7085108d01..6e6052d235 100644 --- a/interface/wx/propgrid/propgrid.h +++ b/interface/wx/propgrid/propgrid.h @@ -1145,6 +1145,8 @@ public: /** Draws item, children, and consecutive parents as long as category is not met. + + @param p Valid, i.e. non-@NULL, property pointer. */ void DrawItemAndValueRelated( wxPGProperty* p ); diff --git a/src/propgrid/propgrid.cpp b/src/propgrid/propgrid.cpp index 149c01bd35..a1ed7af8be 100644 --- a/src/propgrid/propgrid.cpp +++ b/src/propgrid/propgrid.cpp @@ -2588,6 +2588,8 @@ void wxPropertyGrid::RefreshProperty( wxPGProperty* p ) void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty* p ) { + wxCHECK_RET( p, wxS("invalid property id") ); + if ( IsFrozen() ) return;