From 84409dfa0ade3ab03ace69896f1bc3a671a1ac0e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 16 Nov 2020 01:47:59 +0100 Subject: [PATCH] Don't send wxEVT_ACTIVATE to half-destroyed windows in wxMSW This resulted in a crash when WM_ACTIVATE was received from inside wxWindow dtor, executed after wxTopLevelWindowMSW dtor, and passed to a handler defined in wxTopLevelWindowMSW and using its already destroyed members. Perhaps we should avoid dispatching any messages when the window is being destroyed, but it's not totally obvious that this is not going to break something, so for now apply just this minimal fix. Closes #18970. --- src/msw/window.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/msw/window.cpp b/src/msw/window.cpp index 7694caa26f..703d65a93c 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -4296,6 +4296,14 @@ bool wxWindowMSW::HandleActivate(int state, return false; } + if ( m_isBeingDeleted ) + { + // Same goes for activation events sent to an already half-destroyed + // window: this doesn't happen always, but can happen for a TLW using a + // (still existent) hidden parent, see #18970. + return false; + } + wxActivateEvent event(wxEVT_ACTIVATE, (state == WA_ACTIVE) || (state == WA_CLICKACTIVE), m_windowId,