[pygtk] Segfault with set_set_scroll_adjustments_signals and gnome.ui

BJörn Lindqvist bjourne at gmail.com
Thu Sep 11 03:44:31 WST 2008


Hi,

2008/8/29 Herwig Hochleitner <hhochleitner at gmail.com>:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hello!
> My Custom DrawingArea keeps segfaulting me on being destroyed.
> I traced it down to the following minimal example:
>
> [PYTHON]
>
> import gtk
> import gobject
> import gnome.ui
>
> class CustomDrawingArea(gtk.DrawingArea):
>    __gsignals__ = {"set-scroll-adjustments" : (gobject.SIGNAL_RUN_LAST,
> gobject.TYPE_BOOLEAN,
>                                                (gobject.TYPE_OBJECT,
> gobject.TYPE_OBJECT))}
>
>    def __init__(self):
>        gtk.DrawingArea.__init__(self)
>        self.set_set_scroll_adjustments_signal("set-scroll-adjustments")
>
>    def do_set_scroll_adjustments(self, hadjustment, vadjustment):
>        return False
>
> gobject.type_register(CustomDrawingArea)
>
> if __name__ == "__main__":
>    win = gtk.Window()
>    swin = gtk.ScrolledWindow()
>    da = CustomDrawingArea()
>    win.add(swin)
>    swin.add(da)
>    win.show_all()
>    gtk.main()
>
> [/PYTHON]

There are actually two different bugs at work here.

> The segfault happens when deleting the window

See http://bugzilla.gnome.org/show_bug.cgi?id=551699. When you delete
a window, you invoke that windows destroy() method which is supposed
to free up its references to other widgets. Except that it often
doesn't work because many widgets implement the destroy/finalize
scheme wrongly. Others may disagree, but I think it is best to always
terminate your applications using sys.exit(), that way you don't have
to deal with all the problems in gtk's object destruction system.

> or removing the custom widget from the scrolled window (in my
> application this happens dynamically).

I think this happens because your set-scroll-adjustments signal
prototype is wrong. It should return None, not a bool. Like this:

    __gsignals__ = {
        "set-scroll-adjustments" : (gobject.SIGNAL_RUN_LAST,
                                    bool,
                                    (gtk.Adjustment, gtk.Adjustment))}

Gtk isn't smart enough to check that your signal prototype is correct
before calling it.


-- 
mvh Björn


More information about the pygtk mailing list