Delivered-To: garrigue at math.nagoya-u.ac.jp Delivered-To: lablgtk at yquem.inria.fr Message-ID: <4BF5541B.6080509 at lri.fr> Date: Thu, 20 May 2010 17:24:11 +0200 From: Alain Mebsout MIME-Version: 1.0 To: lablgtk at yquem.inria.fr Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: [Lablgtk] Problem with Gtext.iter in menuitem callback Status: U Hi lablgtk, I'm trying to insert some text in a source_buffer when clicking on a menu item (in a popup menu, which shows on right clicking a certain tag). Here is a simplified version of my callback function : let triggers_callback (buffer:GSourceView.source_buffer) ~origin:y z i = let ni = new GText.iter i in match GdkEvent.get_type z with | `BUTTON_PRESS -> buffer#insert ~iter:ni " | new trigger"; (* THIS WORKS FINE *) let z = GdkEvent.Button.cast z in if GdkEvent.Button.button z = 3 then let menu = GMenu.menu () in let image = GMisc.image ~stock:`ADD () in let menuitem = GMenu.image_menu_item ~image ~label:"Add trigger(s) ..." ~packing:menu#append () in ignore(menuitem#connect#activate ~callback:(fun () -> buffer#insert ~iter:ni " | new trigger") (* GTK ERROR *) ); menu#popup ~button:3 ~time:(GdkEvent.Button.time z); true else false | _ -> false The first call to buffer#insert does what it's expected to do but the second one which is connected to the menu item raises a gtk error (and sometimes a segfault if I try to access the iter e.g. with iter#forward_char). It looks like the iter does not exists anymore. I would be grateful if anybody could give me a hint on whether I'm missing something here or if there's strange magic happening in menu items. Here is the gtk error triggered by the second call to buffer#insert : Gtk-WARNING **: Invalid text buffer iterator: either the iterator is uninitialized, or the characters/pixbufs/widgets in the buffer have been modified since the iterator was created. You must use marks, character numbers, or line numbers to preserve a position across buffer modifications. You can apply tags and insert marks without invalidating your iterators, but any mutation that affects 'indexable' buffer contents (contents that can be referred to by character offset) will invalidate all outstanding iterators Gtk-CRITICAL **: gtk_text_buffer_insert: assertion `gtk_text_iter_get_buffer (iter) == buffer' failed Best regards, -- Alain _______________________________________________ Lablgtk mailing list Lablgtk@yquem.inria.fr http://yquem.inria.fr/cgi-bin/mailman/listinfo/lablgtk