Web lists-archives.com

Vala runtime error when inserting child button on Gtk.TextView


I'm porting an application from C# to Vala and have run into an issue.

In C# creating a child anchor on a TextBuffer takes a TextIter by ref.  The associated call in vala does not take that parameter by ref, and upon running the code I get the following error:

(SideCoreVala:1212): Gtk-CRITICAL **: gtk_text_buffer_insert: assertion 'gtk_text_iter_get_buffer (iter) == buffer' failed

(SideCoreVala:1212): 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

Here is the section of Vala code:

      //button to show person window:
      LinkButton linkButton = new LinkButton();
      linkButton.LinkedEntity = person;
      linkButton.clicked.connect (this.show_person_window);

      //attach the button
      TextChildAnchor anchor = bufferResults.create_child_anchor(iter);  // *** <-- not by ref here
      textviewResults.add_child_at_anchor(linkButton, anchor);

And in C# it is...

        SideCoreGtkUI.LinkButton editButton = new SideCoreGtkUI.LinkButton("edit");
        editButton.EntityId = person.getId();
        editButton.EntityType = "SideCore.Person";

        editButton.Clicked += new EventHandler(onButtonEditClicked);
        buttonAnchor = buffer.CreateChildAnchor(ref insertIter);  //*** <--- by ref here
        textviewResults.AddChildAtAnchor(editButton, buttonAnchor);

The LinkButton is just a Gtk.Button with a place to store info of an Entity.  

I've tried to copy the TextIterator and pass the copy when creating the anchor, but that doesn't solve the issue.  Does anyone know the correct way to do this?  Thanks for any direction you're able to provide.

Jason Shortt

gtk-list mailing list