From b88f472291748d129ccf098703d087789a4b401c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 21 Oct 2021 15:33:49 +0100 Subject: [PATCH] Relax the sizer parent check to allow for null parent too Normally non-toplevel windows must have non-null parents, as creating them with null parent would fail, but our own wxTabFrame used in AUI is an example of a window which can have null parent because it's actually never created at all. This does look like a pretty bad hack, but it's very unlikely to happen accidentally, so relax the assertion check added in the previous commit to allow for it. --- src/common/sizer.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/common/sizer.cpp b/src/common/sizer.cpp index 55d0ca40bb..beb1bbf243 100644 --- a/src/common/sizer.cpp +++ b/src/common/sizer.cpp @@ -187,6 +187,17 @@ wxString MakeFlagsCheckMessage(const char* start, const char* whatToRemove) ); } +bool CheckExpectedParentIs(wxWindow* w, wxWindow* expectedParent) +{ + // We specifically exclude the case of a window with a null parent as it + // typically doesn't happen accidentally, but does happen intentionally in + // our own wxTabFrame which is a hack used by AUI for whatever reason, and + // could presumably be also done on purpose in application code. + wxWindow* const parent = w->GetParent(); + + return !parent || parent == expectedParent; +} + wxString MakeExpectedParentMessage(wxWindow* w, wxWindow* expectedParent) { return wxString::Format @@ -249,7 +260,7 @@ wxString MakeExpectedParentMessage(wxWindow* w, wxWindow* expectedParent) #define ASSERT_WINDOW_PARENT_IS(w, expectedParent) \ wxASSERT_MSG \ ( \ - w->GetParent() == expectedParent, \ + CheckExpectedParentIs(w, expectedParent), \ MakeExpectedParentMessage(w, expectedParent) \ )