[gtkada] SOLVED: Re: STORAGE_ERROR on Add, Remove, Add

Preben Randhol randhol at pvv.org
Wed May 9 10:01:49 CEST 2001


Preben Randhol <randhol at pvv.org> wrote on 08/05/2001 (22:25) :
> Arg. I just noticed I cut'n'pasted the wrong error message. The error
> message above was an old from a different error I made.
> 
> This is the error I get:
> 
> Gtk-CRITICAL **: file gtkcontainer.c: line 714 (gtk_container_add):
> assertion `GTK_IS_WIDGET (widget)' failed.
> 
> raised STORAGE_ERROR : stack overflow (or erroneous memory access)
> 
> I'm running gvd on the program now and I see that the ptr that the
> Some_Widget points to change after the Remove.

I found out from the Gtk+ list that I need to call Gtk.Object.Ref on the
Some_Widget before removing it an Unref after Adding again like:


   Add (Container, Some_Widget);
   Ref (Some_Widget);
   Remove (Container, Some_Widget);
   Add (Container, Some_Widget);
   Unref (Some_Widget);

Otherwise the reference counter goes to zero and the Some_Widget gets
destroyed, leaving a dangling ref.

I don't know if this is the behaviour for GtkAda too as the doc says:

   procedure Ref
        (Object             : access Gtk_Object_Record);

   Increment the reference count on the object.

   Since an object is not deleted while its reference count is not null,
   this is a way to keep an object in memory. GtkAda mostly takes care of
   everything, and you should not need this function except in special
   cases.

but if it is, perhpas add to the documentation of Remove.

Note that the widgets reference count will decrease by using Remove so
it may be necessary to call Gtk.Object.Ref on the widget before removing
if you want to use the Widget later. And then call Unref on the widget
after it is used again, e.g. after an Add.

Thanks in advance.

-- 
Preben Randhol ------------------- http://www.pvv.org/~randhol/ --
                 «For me, Ada95 puts back the joy in programming.»




More information about the gtkada mailing list