After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 606751 - Invalid iter when changing a source_buffer during a "changed" event
Invalid iter when changing a source_buffer during a "changed" event
Status: RESOLVED NOTABUG
Product: gtk+
Classification: Platform
Component: Widget: GtkTextView
3.8.x
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2010-01-12 15:24 UTC by zoggy
Modified: 2014-07-28 08:21 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
The file seems to not have been uploaded durint the initial report. (482 bytes, text/x-ocaml)
2010-01-12 15:41 UTC, zoggy
Details
Example with a C program (1.38 KB, text/plain)
2010-06-29 11:11 UTC, zoggy
Details

Description zoggy 2010-01-12 15:24:55 UTC
Hello,

I encounter the following warning:
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

This happens when I set a callback to a "changed" event of a GtkSourceBuffer and when this callback modifies the contents of the buffer.

Here is an example, using the lablgtk2 ocaml bindings.
To compile:
ocamlopt -o gtk.x -I +lablgtk2 lablgtk.cmxa lablgtksourceview2.cmxa testgtk.ml
(You must have ocaml and lablgtk2 installed)
Then launch ./gtk.x .
Each time a character is entered, the string foo is set as text for the buffer and the warning is written in the terminal. This does not occur with GtkTextBuffer.

Regards,

Zoggy
Comment 1 zoggy 2010-01-12 15:41:31 UTC
Created attachment 151257 [details]
The file seems to not have been uploaded durint the initial report.
Comment 2 Ignacio Casal Quinteiro (nacho) 2010-06-25 10:33:50 UTC
See that you can NOT work with iters directly, you must save the position of your iter with a mark and get the iter back from the mark when appropiate.
Comment 3 Ignacio Casal Quinteiro (nacho) 2010-06-26 15:32:15 UTC
Can you confirm if my previous comment was the issue?
Comment 4 zoggy 2010-06-29 11:11:14 UTC
Hello,

may be, may be not. Here is the same example with a C program.
I associate to the "changed" event on a buffer a function which only inserts "hello" in this buffer, using gtk_text_insert_at_cursor.
When inserting, I have the warning of my original post.
So I don't use any iter directly, though I imagine that gtk_text_insert_at_cursor does.
My guess is that iters are still marked as modified when the callback associated to the "changed" event is called, thus giving the warning. I precise that the text is inserted at the right position (at the cursor position, after the text I type in).

The example is compiled with
gcc -o testgtk `pkg-config --libs gtksourceview-2.0` `pkg-config --cflags gtksourceview-2.0` testgtk.c

and launched with ./testgtk
Just type i a letter in the text widget to get the warning.

Regards,

Zoggy
Comment 5 zoggy 2010-06-29 11:11:54 UTC
Created attachment 164880 [details]
Example with a C program
Comment 6 Tobias Mueller 2010-10-11 20:54:03 UTC
Reopening as an example has been provided.
Comment 7 Sébastien Wilmet 2013-03-30 19:15:28 UTC
Not a GtkSourceView issue, it happens with a GtkTextBuffer/View too.
Comment 8 Sébastien Wilmet 2014-07-20 14:48:56 UTC
You must connect to the "insert-text" or "delete-range" signals, so you can keep the location iter valid.
Comment 9 zoggy 2014-07-28 08:21:15 UTC
Great, it works. Thanks !