[Gtk-sharp-list] Buttons from Gtk.Stock and reparenting

Leo Spalteholz leo@thewoodpecker.ca
Mon, 3 Nov 2003 05:07:01 -0800

Ok, this is a little odd (for me anyway :))

I have a class that derives from Gtk.Button (I have some specific 
requirements for buttons such as labels that word wrap in them)  and I'm 
trying to create a button from stock and then reparent the child widget to 
my button class.  So I have the following:

    new public static OButton NewFromStock(string stockID) {
            Button b = Button.NewFromStock(stockID);
            OButton ob = new OButton();
	    // get the child and reparent it
            foreach(Alignment a in b.Children) {

            return ob;

Now this works (as in it displays the stock button content) but then 
immediately crashes as soon as the interface displays.

(<unknown>:1213): GLib-GObject-WARNING **: instance with invalid (NULL) 
class pointer

(<unknown>:1213): GLib-GObject-CRITICAL **: file gsignal.c: line 2490 
(g_signal_emit_valist): assertion `G_TYPE_CHECK_INSTANCE (instance)' 

Unhandled Exception: System.NullReferenceException: A null value was found 
where an object instance was required
in (unmanaged) 06 GLib.Object:g_object_unref (intptr)
in <0x00004> 06 GLib.Object:g_object_unref (intptr)
in <0x0014a> 00 GLib.Object:PerformQueuedUnrefs ()
in <0x0001b> 05 GLib.Object:PerformQueuedUnrefs ()
in (unmanaged) 06 Gtk.Application:gtk_main ()
in <0x00004> 06 Gtk.Application:gtk_main ()
in <0x00007> 00 Gtk.Application:Run ()

Maybe it is choking when it tries to unref the stock Gtk.Button that I 
created which no longer has any children.

Is there something fundementally wrong with my NewFromStock method or is 
that not the problem?   Any help is greatly appreciated.. This has been 
driving me right up the wall all day.  :(