According to the GObject reference manual, object methods should be able to run without program error after their object has been disposed but before it has been finalized. I would like to know whether this implies that an object should not produce critical warnings between disposal and finalization if one of its properties is set.
Here is the situation: I have a GtkFontButton whose “font” property is bound to a setting using g_settings_bind. Due to the language bindings, the GtkFontButton is disposed but not immediately finalized. In this period, the setting can change causing the “font” property to be set. The backtrace from gdb shows that the following critical warnings occur due to an attempt to set the “font” property while the GtkFontButton is disposed:
My suspicion is that some private data is freed on disposal but the widget still tries to useit due to a change in the property “font” that calls the following function hierarchy: gtk_font_button_set_property font_button_set_font_name gtk_font_button_take_font_desc gtk_font_button_update_font_info.
Is this an issue with GtkFontButton or is an application expected to unbind the setting from the “font” property to protect against this, e.g. in a “destroy” signal handler for the GtkFontButton instance?
Thanks for confirming. I was about to raise an issue but thought I would look at how other widgets using gtk_widget_class_bind_template_child_private protect against use of private state after disposal . Looking at GtkAboutDialog, I can’t see how this is done. Testing with the code below suggests that gtk_about_dialog_set_version produces critical warnings after disposal (but not if there is no disposal). Is the test code below in some way flawed?
/* gcc test_set_after_dispose.c `pkg-config --cflags --libs gtk+-3.0` */
int main (int argc, gchar *argv)
gtk_init (&argc, &argv);
about = gtk_about_dialog_new ();
gtk_about_dialog_set_version (GTK_ABOUT_DIALOG (about), "1.2.3");
/* Should uncommenting this disposal expression affect the subsequent
* `gtk_about_dialog_set_version` ? I didn't think so but doing so
* results in critical warnings from `gtk_about_dialog_set_version`.
g_object_run_dispose (G_OBJECT (about));
gtk_about_dialog_set_version (GTK_ABOUT_DIALOG (about), "2.3.4");
I’m not a GTK developer but that seems wrong to me. Best to create an issue for all these things. Especially because it actually means a problem in practice for bindings this seems like something that should be fixed.
Also more developers should run their code with G_DEBUG=fatal_criticals