Vala runtime error when inserting child button on Gtk.TextView

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Vala runtime error when inserting child button on Gtk.TextView

Jason Shortt
Hello,

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);
      linkButton.show_all();

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);
        editButton.ShowAll();

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
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-list
Reply | Threaded
Open this post in threaded view
|

RE: Vala runtime error when inserting child button on Gtk.TextView

Jason Shortt
Hey Guys,

I was able to find a solution to my problem.  In Vala, after inserting the child button I re-set the TextIterator to the end position of the TextBuffer.  Seems to have solved the issue.  Here is the updated code:

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

      //attach the button
      TextChildAnchor anchor = bufferResults.create_child_anchor(iter);
      textviewResults.add_child_at_anchor(linkButton, anchor);
      bufferResults.get_end_iter(out iter);  // <----  This Fixes the runtime error.
      linkButton.show_all();


Jason

_______________________________________________
gtk-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-list