From 0dd099f3c58dcf1bb6a71365bdf96831cd16b420 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 7 Feb 2014 14:35:48 +0000 Subject: [PATCH] Avoid crashes when deleting owned top level windows. Don't delay the TLW destruction if it has a parent and its parent is already being deleted: we can't delay the inevitable in this case and only succeed in making the program crash if we try. Closes #15743. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_3_0_BRANCH@75833 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/toplvcmn.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/common/toplvcmn.cpp b/src/common/toplvcmn.cpp index 3503a15ddc..ef693690c5 100644 --- a/src/common/toplvcmn.cpp +++ b/src/common/toplvcmn.cpp @@ -101,6 +101,16 @@ wxTopLevelWindowBase::~wxTopLevelWindowBase() bool wxTopLevelWindowBase::Destroy() { + // We can't delay the destruction if our parent is being already destroyed + // as we will be deleted anyhow during its destruction and the pointer + // stored in wxPendingDelete would become invalid, so just delete ourselves + // immediately in this case. + if ( wxWindow* parent = GetParent() ) + { + if ( parent->IsBeingDeleted() ) + return wxNonOwnedWindow::Destroy(); + } + // delayed destruction: the frame will be deleted during the next idle // loop iteration if ( !wxPendingDelete.Member(this) )