From: Vadim Zeitlin Date: Mon, 4 Jan 2010 12:51:48 +0000 (+0000) Subject: Add assert checking that window has no event handlers when destroyed. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/4b621e4ce48e0776fedaf08c927d161257b25222 Add assert checking that window has no event handlers when destroyed. Forgetting to pop custom event handlers pushed onto the window before it is destroyed will result in a crash later on, so try to detect this immediately with an assert. We might want to forcefully pop them off too, this could result in memory leaks but would be still better than crashing. Closes #11533. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63065 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index 847f6dec9f..b7a70c15e1 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -322,6 +322,12 @@ wxWindowBase::~wxWindowBase() // we weren't a dialog class wxTopLevelWindows.DeleteObject((wxWindow*)this); + // Any additional event handlers should be popped before the window is + // deleted as otherwise the last handler will be left with a dangling + // pointer to this window result in a difficult to diagnose crash later on. + wxASSERT_MSG( GetEventHandler() == this, + wxT("any pushed event handlers must have been removed") ); + #if wxUSE_MENUS // The associated popup menu can still be alive, disassociate from it in // this case