From ffac9368820d021978d58db0ac33b2e60ab0871e Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Tue, 22 Oct 2019 19:51:50 -0700 Subject: [PATCH] Fix crash in propgrid sample, see #18537 --- samples/propgrid/propgrid.cpp | 48 +++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/samples/propgrid/propgrid.cpp b/samples/propgrid/propgrid.cpp index d1382516aa..4cce1563e2 100644 --- a/samples/propgrid/propgrid.cpp +++ b/samples/propgrid/propgrid.cpp @@ -2985,21 +2985,23 @@ void FormMain::OnSetPropertyValue( wxCommandEvent& WXUNUSED(event) ) void FormMain::OnInsertChoice( wxCommandEvent& WXUNUSED(event) ) { wxPropertyGrid* pg = m_pPropGridManager->GetGrid(); - wxPGProperty* selected = pg->GetSelection(); - const wxPGChoices& choices = selected->GetChoices(); - // Insert new choice to the center of list + if (selected) + { + const wxPGChoices& choices = selected->GetChoices(); - if ( choices.IsOk() ) - { - int pos = choices.GetCount() / 2; - selected->InsertChoice("New Choice", pos); - } - else - { - ::wxMessageBox("First select a property with some choices."); + if ( choices.IsOk() ) + { + // Insert new choice to the center of list + + int pos = choices.GetCount() / 2; + selected->InsertChoice("New Choice", pos); + return; + } } + + wxMessageBox("First select a property with some choices."); } // ----------------------------------------------------------------------- @@ -3007,21 +3009,23 @@ void FormMain::OnInsertChoice( wxCommandEvent& WXUNUSED(event) ) void FormMain::OnDeleteChoice( wxCommandEvent& WXUNUSED(event) ) { wxPropertyGrid* pg = m_pPropGridManager->GetGrid(); - wxPGProperty* selected = pg->GetSelection(); - const wxPGChoices& choices = selected->GetChoices(); - // Deletes choice from the center of list + if (selected) + { + const wxPGChoices& choices = selected->GetChoices(); - if ( choices.IsOk() ) - { - int pos = choices.GetCount() / 2; - selected->DeleteChoice(pos); - } - else - { - ::wxMessageBox("First select a property with some choices."); + if ( choices.IsOk() ) + { + // Deletes choice from the center of list + + int pos = choices.GetCount() / 2; + selected->DeleteChoice(pos); + return; + } } + + wxMessageBox("First select a property with some choices."); } // -----------------------------------------------------------------------