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.
This commit is contained in:
Andreas Kling 2019-04-06 21:15:13 +02:00
commit e74f32ae40
Notes: sideshowbarker 2024-07-19 14:48:02 +09:00

View file

@ -28,8 +28,12 @@ void GWidget::child_event(GChildEvent& event)
layout()->add_widget(static_cast<GWidget&>(*event.child()));
}
if (event.type() == GEvent::ChildRemoved) {
if (event.child() && event.child()->is_widget() && layout())
if (layout()) {
if (event.child() && event.child()->is_widget())
layout()->remove_widget(static_cast<GWidget&>(*event.child()));
else
invalidate_layout();
}
}
return GObject::child_event(event);
}