In some cases, when removing a GtkWidget from a GtkPaned, the code enters in an infinite loop, showing over and over again the message
(test_gtk4:18277): Gtk-CRITICAL **: 00:22:19.677: gtk_widget_get_parent: assertion ‘GTK_IS_WIDGET (widget)’ failed
This happens because in the method gtk_paned_set_focus_child() there is a loop to find the top element with the focus. But that loop only stops when it arrives to the paned itself.
In some cases this condition is never met. An example is if inside the paned is a GtkBox with a button, and pressing the button removes the GtkBox from the GtkPaned. This, by itself, doesn't present any problem. But if the button callback removes first the button from the GtkBox, and then the callback removes the GtkBox from the GtkPaned, the loop in gtk_paned_set_focus_child() enters in an infinite loop, because the GtkButton, which was the widget with the focus, isn't inside the GtkPaned, so asking recursively for their parents will never arrive to the GtkPaned.
This patch fixes this by stopping the loop if the parent is NULL.