Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Register
  • Sign in
  • gtk gtk
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
  • Issues 1.6k
    • Issues 1.6k
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 238
    • Merge requests 238
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Container Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • GNOMEGNOME
  • gtkgtk
  • Issues
  • #5834
Closed
Open
Issue created May 13, 2023 by Jason Francis@jfContributor

dispose_template causes unparenting twice when using widget subclasses

Steps to reproduce

  1. Compile and run this snippet: https://gitlab.gnome.org/-/snippets/5743
  2. Close the window
  3. See the critical:
    (test:487081): Gtk-CRITICAL **: 11:31:54.392: gtk_widget_unparent: assertion 'GTK_IS_WIDGET (widget)' failed

Current behavior

Partial backtrace of the critical:

...
#2  0x00007ffff7884327 in gtk_window_dispose (object=0x4ff960) at ../gtk/gtkwindow.c:2563
#3  0x00000000004013fd in example_template_dispose (object=0x4ff960) at ../main.c:36
#4  0x00007ffff7479974 in g_object_unref (_object=0x4ff960) at ../gobject/gobject.c:3891
#5  g_object_unref (_object=0x4ff960) at ../gobject/gobject.c:3802
#6  0x00007ffff7aa105d in gtk_widget_stack_free_elements (end=<optimized out>, start=<optimized out>) at ../gdk/gdkarrayimpl.c:95
#7  gtk_widget_stack_clear (self=0x7fffffffd290) at ../gdk/gdkarrayimpl.c:104
...

On the line:

2563      g_clear_pointer (&priv->child, gtk_widget_unparent);

So the child is unparented (and freed) already in gtk_widget_dispose_template() by the time gtk_window_dispose() runs, but GtkWindow still holds a dangling pointer to the child.

Expected outcome

gtk_widget_dispose_template() should not unparent child widgets that are already "owned" by a widget subclass. But it is unclear how to figure that out, without changing the implementation of every buildable_add_child.

Version information

GTK 4.11.1, Fedora rawhide

Assignee
Assign to
Time tracking