From d0024bd9f735c4d5aca7eb5024c488c12037f176 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Mon, 5 Dec 2022 19:33:20 -0500 Subject: [PATCH] Properties: clear text ctrl from unit binder before it is destroyed The lifetime of this text ctrl is managed by the property grid, so we need to catch when it is hidden before destruction in order to avoid stale pointers being used to handle unit change events. Credit to @dsa-t for the fix --- common/widgets/unit_binder.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/common/widgets/unit_binder.cpp b/common/widgets/unit_binder.cpp index 708281600f..1a103eca0d 100644 --- a/common/widgets/unit_binder.cpp +++ b/common/widgets/unit_binder.cpp @@ -642,5 +642,13 @@ void PROPERTY_EDITOR_UNIT_BINDER::SetControl( wxWindow* aControl ) nullptr, this ); m_valueCtrl->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( PROPERTY_EDITOR_UNIT_BINDER::onClick ), nullptr, this ); + m_valueCtrl->Bind( wxEVT_SET_FOCUS, &PROPERTY_EDITOR_UNIT_BINDER::onSetFocus, this ); + + m_valueCtrl->Bind( wxEVT_SHOW, + [&]( wxShowEvent& e ) + { + if( !e.IsShown() ) + SetControl( nullptr ); + } ); } }