[bug] ref_count+=2 in gtk_*_add





i finaly found some time to track down a very annoing and serious bug.

symptom:

everytime i pressed a close button in any window of gubi, it crashed
with a BadWindow error.

reason:

this is due to a call to gtk_style_set_background() after the mouse
button got released, which in turn called gdk_window_set_background()
and therefore XSetWindowBackground() with the buttons window as
argument wich was already destroyed. but the GtkButton "Close" didn't
have neither GTK_NEED_DESTROY nor GTK_BEING_DESTROYED set in the flags.
this happend because of a prior call to gtk_widget_destroy() wich was
ignored because of the buttons ref_count being 1.
but the buttons parent (here the main window) still got destroyed and
therefore its corresponding X-window children got destroyed as well.

being up to this point, i figured, i had to track down the ref_count:

the button actualy got added to it's container via the
gtk_container_add() function wich caused gtk_box_pack_start_defaults()
to get invoked.
now gtk_container_add() does a gtk_widget_set_parent() and afterwards,
gtk_box_pack_start_defaults() does a gtk_widget_set_parent() as well.
and, guess what - gtk_widget_set_parent() increments the ref_count of
the child widget.

conclusion:

for now, i added a call to gtk_object_unref() in
gtk_box_pack_start_defaults(), which fixes this prob for the short
term, but there need to be a better way as gtk_widget_set_parent()
does some else things like setting internal styles and stuff.
also there are some else functions that introduce the same
problem as gtk_box_pack_start_defaults() (gtk_box_add):
 gtk_bin_add;
 gtk_button_add;
 gtk_list_add;
 gtk_menu_shell_add;
 gtk_notebook_add;
 gtk_scrolled_window_add;
 gtk_table_add;
(i didn't look into each one of them, this is just from grep | sed).

so, what should the final solution look like?


BTW, i think the special case ref_count>0 in gtk_widget_destroy()
should be a g_return_if_fail case, as most times this will indicate
that there must be something else seriously wrong.


PS:  yep - i know, my english is crap ;)

---
ciaoTJ



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]