Re: [gtk-list] Re: Gtk--: (resend) recent changes with GTK_OBJECT_CONSTRUCTED ??



On Thu, 11 Mar 1999 Robert_Gasch/PeopleSoft@peoplesoft.com wrote:

> 
> 
> > > Robert Gasch wrote:
> > > some code that used to work for quite a while without problems is partially
> > > broken
> > > since my latest upgrade to Gtk+ 1.1.16 and Gtk-- 0.11.2. I have some dialog
> > > boxes
> > > that override the delete_impl method with the following code:
> > >      this->hide();
> > >      return;
> > >
> > > This used to work fine (it still works), but now gives me the following
> > > error/warning:
> > >
> > > Gtk-CRITICAL **: file gtkwidget.c: line 1388 (gtk_widget_destroy):
> > > assertion `GTK_OBJECT_CONSTRUCTED (widget)' failed.
> > looks like it calls gtk_widget_destroy twice for same object. (or maybe the
> > object is poorly constructed..)

gtk_widget_destroy() can be called infinite times on a widget as long as it
is existant (i.e. ref_count>0).

> I don't think so (at least not in my code) ...
> 
> > It would help to find the problem if we had stack dumps of the call to
> > that gtk_widget_destroy where the error happens.
> > (gdb ./myproggy ; break gtk_widget_destroy ; condition 1
> !GTK_OBJECT_CONSTRUCTED(widget) ; run ; where)
> 
> Please see the attached stack trace ...
> 
> > I dunno what has changed - but it might be that gtk+ now more strictly catches
> > problems in this area -- we should look into it more carefully.. :)

some widgets (objects) require construction arguments, e.g. a hscrollbar requires
an adjustment to work properly. such widgets introduce GTK_ARG_CONSTRUCT arguments
and gtk+ usually asures that the widget either gets the construction parameters
assigned that the user provides, or if the user doesn't provide any, passes
default values for the construction parameters.

the thing is,

gtk_object_new (GTK_TYPE_HSCROLLBAR,
                "GtkHScrollbar::adjustment", adjustment,
                NULL);
or
gtk_hscrollbar_new (adjustment);
or
gtk_widget_new (GTK_TYPE_HSCROLLBAR,
                "GtkHScrollbar::adjustment", adjustment,
                NULL);

will construct the scrollbar with the user's adjustment, while

gtk_object_new (GTK_TYPE_HSCROLLBAR, NULL);
or
gtk_widget_new (GTK_TYPE_HSCROLLBAR, NULL);

will construct the scrollbar with an adjustment parameter of NULL, in
which case the scrollbar will create a default adjustment.
in either case, the scrollbar is returned with the GTK_CONSTRUCTED
flag set.

however, some places still use

object = gtk_type_new (GTK_TYPE_HSCROLLBAR);

which will return an unconstructed object. this function is actually
deprecated for normal object construction since people that use
gtk_type_new() have to either assure that they fully construct the
object before normal usage or at least call
gtk_object_default_construct (object); so gtk can default construct
the obejct.

> Yes, I will try to further remove extraneous code from my testcase and see if
> points us/you/anybody in the right direction ...

i think the code to blame here is most probably the Gtk-- object construction
stuff, we need to know what widget is created wrongly here though.

try to debug your program and in gdb you do:

1395      g_return_if_fail (GTK_IS_WIDGET (widget));
(gdb) n
1396      g_return_if_fail (GTK_OBJECT_CONSTRUCTED (widget));
(gdb) n
> Gtk-CRITICAL **: file gtkwidget.c: line 1396 (gtk_widget_destroy): assertion
> `GTK_OBJECT_CONSTRUCTED (widget)' failed.
1398      gtk_object_destroy ((GtkObject*) widget);
> 1399    }
(gdb) print *(GtkWidgetClass*)widget->object.klass

this will dump the widget's klass structure, which will tell us what kinda
widget is tryed to be destructed here.

BTW, gtk should actually check more stricly for this flag, as one usually
     can't realize (and map) widgets that are not constructed, so i guess
     we should place a g_return_if_fail (GTK_OBJECT_CONSTRUCTED (widget));
     in gtk_widget_realize() as well.

> 
> Thanks for all the help
> --> Robert
> 

---
ciaoTJ



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