From 27110bfa72f11f32010c6555a0fcbb5dbc643579 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 27 Oct 2017 02:07:01 +0200 Subject: [PATCH] Gracefully handle parent disappearance in wxGenericProgressDialog Use a weak reference to the parent instead of a pointer to avoid crashing if the parent TLW is destroyed before wxGenericProgressDialog itself is. This is unlikely to happen in C++ code, where objects of this class are typically created on the stack, but can happen in e.g. wxPython where this is not the case. Closes #16378. --- include/wx/generic/progdlgg.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/wx/generic/progdlgg.h b/include/wx/generic/progdlgg.h index 77b90f76f4..e5f4bb0eb3 100644 --- a/include/wx/generic/progdlgg.h +++ b/include/wx/generic/progdlgg.h @@ -12,6 +12,7 @@ #define __PROGDLGH_G__ #include "wx/dialog.h" +#include "wx/weakref.h" class WXDLLIMPEXP_FWD_CORE wxButton; class WXDLLIMPEXP_FWD_CORE wxEventLoop; @@ -183,8 +184,9 @@ private: *m_estimated, *m_remaining; - // parent top level window (may be NULL) - wxWindow *m_parentTop; + // Reference to the parent top level window, automatically becomes NULL if + // it it is destroyed and could be always NULL if it's not given at all. + wxWindowRef m_parentTop; // Progress dialog styles: this is not the same as m_windowStyle because // wxPD_XXX constants clash with the existing TLW styles so to be sure we