Re: Problem with markers in sourceview

Jacques Garrigue <[email protected]>
Newsgroups gmane.comp.lang.ocaml.lib.gtk
Message-ID <[email protected]>
From: Mike Spivey <[email protected]>
> This test program allows markers to be set on lines in a GSourceView
> widget by clicking in the left margin.  On my setup (OCaml 3.10.2-3,
> Lablgtk 2.10.1-2, Ubuntu Intrepid), GTK shows critical errors after I
> click a couple of times.
> 
> (bug:12461): GLib-GObject-CRITICAL **: g_object_unref: assertion
> `G_IS_OBJECT (object)' failed
> 
> I've deliberately made the program turn over lots of memory; without the
> added code, it takes thirty clicks or so before the same message appears.
> 
> What am I doing wrong?
> 
> -- Mike

Nothing wrong on you side. This looks like a bug in LablGtkSourceView
(which was recently merged into lablgtk2), which assumed that a newly
created marker was owned by the user, whereas the documentation says
that it is owned by the buffer.
Here is a patch that fixes the problem (just removes the _new suffix)

Index: src/ml_gtksourceview.c
===================================================================
--- src/ml_gtksourceview.c	(revision 1429)
+++ src/ml_gtksourceview.c	(working copy)
@@ -361,7 +361,7 @@
 ML_1 (gtk_source_buffer_begin_not_undoable_action, GtkSourceBuffer_val, Unit)
 ML_1 (gtk_source_buffer_end_not_undoable_action, GtkSourceBuffer_val, Unit)
 ML_4 (gtk_source_buffer_create_marker, GtkSourceBuffer_val,
-      String_option_val, String_option_val, GtkTextIter_val, Val_GtkSourceMarker_new)
+      String_option_val, String_option_val, GtkTextIter_val, Val_GtkSourceMarker)
 ML_3 (gtk_source_buffer_move_marker, GtkSourceBuffer_val,
       GtkSourceMarker_val, GtkTextIter_val, Unit)
 ML_2 (gtk_source_buffer_delete_marker, GtkSourceBuffer_val,


[Your code]
> 
> let _ = GMain.init ()
> 
> let gensym = ref 0
> 
> let source_click (view : GSourceView.source_view) ev =
>   if GdkEvent.get_type ev = `BUTTON_PRESS
>       && view#get_window_type (GdkEvent.get_window ev) = `LEFT then begin
>     let (x, y) =
>       view#window_to_buffer_coords `LEFT
> 	(truncate (GdkEvent.Button.x ev))
> 	(truncate (GdkEvent.Button.y ev)) in
>     let (iter, _) = view#get_line_at_y y in
>     let buf = view#source_buffer in
>     let marks =
>       List.filter (fun mk -> mk#get_type = "breakpoint")
> 	(buf#get_markers_in_region iter iter) in
>     if marks <> [] then
>       buf#delete_marker (List.hd marks)
>     else begin
>       incr gensym;
>       ignore (buf#create_marker ~name:(string_of_int !gensym)
> 	~typ:"breakpoint" iter);
>     end
>   end;
> 
>   (* Create lots of garbage *)
>   let rec loop n xs = if n = 0 then () else loop (n-1) (n::xs) in
>   loop 1000000 [];
> 
>   (* Swallow the event *)
>   true
> 
> let main () =
>   let win = GWindow.window ~width:100 ~height:100 () in
>   let buf = GSourceView.source_buffer ~text:"1\n2\n3\n" () in
>   let view =
>     GSourceView.source_view ~source_buffer:buf
>       ~show_line_markers:true
>       ~packing:win#add () in
>   view#set_marker_pixbuf "breakpoint"
>     (GdkPixbuf.from_file "/usr/share/pixmaps/apple-red.png");
>   ignore (view#event#connect#button_press (source_click view));
>   win#show ();
>   GMain.main ()
> 
> let _ = main ()
> 
> 
> 
> _______________________________________________
> Lablgtk mailing list
> [email protected]
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/lablgtk
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.