From 1903c9615ea885fe22f939e148b341919e2bbe6f Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Tue, 31 Oct 2017 20:47:45 +0100 Subject: [PATCH] TLW pending delete shouldn't be reported as the top window Because top windows can (and do) act as parents for certain dialogs, a window already pending delete shouldn't be explicitly reported as the top window because all dialogs which would use it as a parent would be destroyed at nearest idle cycle. Closes #17982. --- src/common/appcmn.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/common/appcmn.cpp b/src/common/appcmn.cpp index 022b5e6fcf..bb947053a4 100644 --- a/src/common/appcmn.cpp +++ b/src/common/appcmn.cpp @@ -170,8 +170,25 @@ void wxAppBase::CleanUp() wxWindow* wxAppBase::GetTopWindow() const { wxWindow* window = m_topWindow; - if (window == NULL && wxTopLevelWindows.GetCount() > 0) - window = wxTopLevelWindows.GetFirst()->GetData(); + + // If there is no top window or it is about to be destroyed, + // we need to search for the first TLW which is not pending delete + if ( !window || wxPendingDelete.Member(window) ) + { + window = NULL; + wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetFirst(); + while ( node ) + { + wxWindow* win = node->GetData(); + if ( !wxPendingDelete.Member(win) ) + { + window = win; + break; + } + node = node->GetNext(); + } + } + return window; }