From: Robin Dunn Date: Tue, 26 Sep 2006 19:52:32 +0000 (+0000) Subject: If a TLW's default item is not an immediate child then it can be left X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/f09df8b2ea9a005117997c020ab222736805c5d4 If a TLW's default item is not an immediate child then it can be left with a dangling pointer when the child is deleted, so check for it in the child's dtor. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41469 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index ccd678019e..2c79fc55e6 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -292,6 +292,18 @@ wxWindowBase::~wxWindowBase() wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") ); + // reset the top-level parent's default item if it is this widget + if ( m_parent ) + { + wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent((wxWindow*)this), + wxTopLevelWindow); + + if ( tlw && tlw->GetDefaultItem() == this ) + tlw->SetDefaultItem(NULL); + if ( tlw && tlw->GetTmpDefaultItem() == this ) + tlw->SetTmpDefaultItem(NULL); + } + // reset the dangling pointer our parent window may keep to us if ( m_parent ) {