On Thu, Jun 17, 2010 at 09:07:46AM +0800, Gregory Hosler wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Hi all,
> 
> I have an application where I'm making use of animated gifs on a 
> GtkTextBuffer.
> I set a timer (g_timeout_add()) to remove the animated character after a small
> period of time (10 secs in this case).
> 
> The argument to the timer callback includes a pointer to the text buffer
> GtkTextChildAnchor in front of where I inserted my animation. The idea is that
> inside the timeout, I insert a static copy of the gif, and do a
> gtk_text_buffer_delete() of the iter's before and after the animation.
> 
> This works about 99.999% of the time.
> 
> In some rare circumstances, by the time that the timer callback is called, the
> GtkTextChildAnchor has been deleted.
> 
> To guard against this, I tested the GtkTextChildAnchor with
> GTK_IS_TEXT_CHILD_ANCHOR(), but on occassion, I will get a segfault on the
> GTK_IS_TEXT_CHILD_ANCHOR() (the address of the GtkTextChildAnchor is still a
> valid address).
> 
> I'm thinking that the GtkTextChildAnchor has been deleted, the memory used for
> something else, and the GTK_IS_TEXT_CHILD_ANCHOR() is seg faulting as a 
> result.
> 
> Question: how might I avoid this seg fault situation ? Will "GTK_IS_WIDGET()"
> help to determine if the GtkTextChildAnchor is still alive before testing it
> with GTK_IS_TEXT_CHILD_ANCHOR() ? or is there a better way of doing this ?

The standard rule is: if you permanently use an object take a reference
with g_object_ref().  Then it can't be finalized unless you release
the reference.

See also the description of gtk_text_child_anchor_get_deleted().

You can get notified when an object is finalized, but this is not a case
where you should do it.

Yeti

_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to