Re: [gtk-list] problem with gtk_signal_connect_object




On Tue, 19 May 1998, Stefan Wille wrote:
> 
> >From what I understand, the function gtk_signal_connect_object connects 
> a signal of one object to a method of another. If the second objects 
> gets destroyed, its method shouldn't be called anymore, since a method 
> should never be invoked on a destroyed object.
> 
> But this happens in my program, causing seg faults. It seems like
> gtk doesn't disconnect connections to an object that gets destroyed.
>

gtk_signal_connect_object() doesn't actually do anything to the
"receiver," I don't think, you could actually use any pointer you want
there, or even NULL. The pointer is simply stored and passed to the
callback. 
 
>   gtk_widget_destroy (receiver);
>   printf ("destroyed object %p\n", receiver);
> 
>   gtk_signal_emit_by_name (GTK_OBJECT(sender), "button_press_event",
> NULL);
> 

You just can't do this, it will SEGV because the callback gets a pointer
to deallocated memory. You have to organize the program differently. 

If you need to remove a callback, you can save the return value of
gtk_signal_connect and use that to remove the callback at a later time.
I'm not at home to look at the source, but you should be able to find the
relevant information in the Gtk headers (gtkmain.h or gtksignal.h).

Havoc Pennington ==== http://pobox.com/~hp




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