From e74f32ae4038127935433d703465178b6c0fa888 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 6 Apr 2019 21:15:13 +0200 Subject: [PATCH] LibGUI: Always invalidate layout on GWidget child removal. This code can get a bit confused when the child is destroyed before we handle the ChildRemoved event. In those cases, the GChildEvent::child() getter will return nullptr as it's backed by a WeakPtr. To work around this issue, just always invalidate the layout for now. This can be made a lot tighter in the future. --- LibGUI/GWidget.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/LibGUI/GWidget.cpp b/LibGUI/GWidget.cpp index 738d6538282..764037870d7 100644 --- a/LibGUI/GWidget.cpp +++ b/LibGUI/GWidget.cpp @@ -28,8 +28,12 @@ void GWidget::child_event(GChildEvent& event) layout()->add_widget(static_cast(*event.child())); } if (event.type() == GEvent::ChildRemoved) { - if (event.child() && event.child()->is_widget() && layout()) - layout()->remove_widget(static_cast(*event.child())); + if (layout()) { + if (event.child() && event.child()->is_widget()) + layout()->remove_widget(static_cast(*event.child())); + else + invalidate_layout(); + } } return GObject::child_event(event); }