Skip to content

gtkwidget: Don’t double-unparent templated children managed by subclasses

If a GtkWidget subclass (for example, AdwBin) manages its own children by overriding GtkBuildable.add_child, it will often have its own internal pointer to the children, and call gtk_widget_set_parent() on them itself.

If a subclass of that class (for example, a custom widget derived from AdwBin) has templated children bound using gtk_widget_class_bind_template_child(), this would previously also mean the subclass’ call to gtk_widget_dispose_template() unparents that child from the widget.

This clashed with the child management done by the parent class (AdwBin in this example), leading to the child being unparented twice, and hence undefined behaviour.

To fix this, track which bound children have been parented into the widget using the default GtkBuildable.add_child implementation. For those which have, unparent them when gtk_widget_dispose_template() is called. For those which have not (i.e. because they are being managed by the AdwBin implementation in this example), do not unparent them. However, still clear the bound pointer for them to NULL.

Signed-off-by: Philip Withnall pwithnall@gnome.org

Fixes: #5834

Closes #5834

Merge request reports

Loading