Crash on CanvasGroup destruction


(Please Cc: me the replies, as I'm not on the list. If it's not the
correct list, please point me to the correct one.)

The following code snippet creates a Gtk window, with a root canvas
inside it. Then, a subclass (called Player) creates a CanvasGroup
inside this root canvas. This CanvasGroup simply contains a RichText
item. A timer is set up, and the role of the method called by the timer
is to update the text displayed by the RichText item, and to increment
the counter. When this counter reaches 10, it detroys the CanvasGroup
in order to delete the RichText from the interface.

Unfortunately, the Python interpreter segfaults once the CanvasGroup
has been destroyed. The stack trace is the following:

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1210565984 (LWP 21630)]
gnome_canvas_request_update (canvas=0x0) at gnome-canvas.c:3494
3494            GNOME_CANVAS_GET_CLASS (canvas)->request_update (canvas);
(gdb) bt
#0  gnome_canvas_request_update (canvas=0x0) at gnome-canvas.c:3494
#1  0xb7137ca6 in request_update (data=0x8298c88) at gnome-canvas-rich-text.c:1683
#2  0xb7aa4451 in g_idle_dispatch (source=0x82fe610, callback=0x8298c88, user_data=0x8298c88) at gmain.c:3796
#3  0xb7aa5e2c in IA__g_main_context_dispatch (context=0x81dd0e8) at gmain.c:1916
#4  0xb7aa9176 in g_main_context_iterate (context=0x81dd0e8, block=1, dispatch=1, self=0x825a120)
    at gmain.c:2547
#5  0xb7aa9537 in IA__g_main_loop_run (loop=0x82ab960) at gmain.c:2751
#6  0xb77474e1 in IA__gtk_main () at gtkmain.c:1003
#7  0xb79dc7d3 in init_gtk () from /var/lib/python-support/python2.4/gtk-2.0/gtk/
#8  0x080b9170 in PyEval_EvalFrame ()
#9  0x080ba675 in PyEval_EvalCodeEx ()
#10 0x080ba6d9 in PyEval_EvalCode ()
#11 0x080dd007 in PyRun_FileExFlags ()
#12 0x080dd204 in PyRun_SimpleFileExFlags ()
#13 0x08055ba8 in Py_Main ()
#14 0x08055032 in main ()

It seems that Gtk tries to update the deleted CanvasGroup.

Attached is the Python code demonstrating the problem. Before
executing, one needs to patch python-gnome2, in order to add the
get_buffer() method of the RichText class. Patch is attached to this

Am I mis-using GnomeCanvas ? Or is this a bug ?

Thanks for your help !


PETAZZONI Thomas - thomas petazzoni enix org 
http://{thomas,sos,kos} - Jabber: thomas petazzoni jabber dk
http://{agenda,livret} -
Fingerprint : 0BE1 4CF3 CEA4 AC9D CC6E  1624 F653 CB30 98D3 F7A7
import pygtk
import gtk
import gobject
import gnomecanvas

class Player:
  def __init__(self, rootitem):
    self.count = 0

    self.canvas = rootitem.add(gnomecanvas.CanvasGroup)

    self.label = self.canvas.add(
      x = 100,
      y = 0,
      width = 190,
      height = 100,
      anchor = gtk.ANCHOR_N,
      editable = False,
      cursor_visible = False,
      justification = gtk.JUSTIFY_CENTER
    self.buffer = self.label.get_buffer()
    self.tag = self.buffer.create_tag("toto", font = "Sans 12", foreground = "black",
                                      editable = False, editable_set = True)

    gobject.timeout_add(500, self.update_position)

  def stop(self):
    if self.canvas == None:
    self.canvas = None

  def update_position(self):
    self.buffer.delete(self.buffer.get_bounds()[0], self.buffer.get_bounds()[1])
    if self.count > 10:
      return False
    self.count += 1
                                 "Blabla %d" % (self.count), self.tag)
    return True

# create a new window
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
canvas = gnomecanvas.Canvas()
canvas.set_size_request(800, 600)
canvas.set_scroll_region(0,0, 800, 600)
rootitem = canvas.root()
player = Player(rootitem)
This patch is needed to add the binding for the
GnomeCanvasRichText.get_buffer() method. It applies on top on gnome-python

diff -ru gnome-python-2.12.3/gnomecanvas/canvas.defs
--- gnome-python-2.12.3/gnomecanvas/canvas.defs	2005-06-08 12:00:08.000000000 +0200
+++	2006-06-18 13:47:45.000000000 +0200
@@ -389,6 +389,12 @@
+(define-method get_buffer
+  (of-object "GnomeCanvasRichText")
+  (c-name "gnome_canvas_rich_text_get_buffer")
+  (return-type "GtkTextBuffer*")
 (define-method scroll_to
   (of-object "GnomeCanvas")
   (c-name "gnome_canvas_scroll_to")
Seulement dans patch-stamp

Attachment: signature.asc
Description: PGP signature

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