Temporary TextBuffer causing segmentation faults

I have a script where the program accepts lines of text that contain a
sort of odd markup that looks similar to XML. In order to convert that
markup to usable information, like text colors and whatnot, I take this
text and create a temporary buffer before inserting it into the actual
text buffer it will end up in. However, sometimes, when inserting text
from the temporary buffer to the main buffer, I get segmentation faults.

The terminal shows:
./archlich-lib.rb:962: [BUG] Segmentation fault
ruby 1.8.6 (2007-03-13) [x86_64-linux]

Aborted

Lines 959 to 963 are:
if (widget.buffer.end_iter.class == Gtk::TextIter and
tbuffer.start_iter.class == Gtk::TextIter and tbuffer.end_iter.class ==
Gtk::TextIter)
widget.buffer.insert_range(widget.buffer.end_iter, tbuffer.start_iter,
tbuffer.end_iter)
end

(the conditionals are me trying to figure out just what is going on)

the ‘tbuffer’ variable is defined as follows, on line 782:
tbuffer = Gtk::TextBuffer.new(widget.buffer.tag_table)

It doesn’t always happen, either. At first, this code worked great. As
the program got larger and larger, these segmentation faults started
becoming more and more frequent. Recently, it is getting to where I can
hardly run the program without running into a segmentation fault.

Is there anything that I can do about this? Alternatively, is it
possible to simply search a text buffer using a regular expression (IE,
via the #forward_search function)? I suppose I could just insert the
text into the main buffer without the temporary buffer and attempt to
manipulate it there, but that would be… troublesome. Considering that
this code seems to work intermittently, I’m wondering if this is
something of a bug in GTK.

  • Andrew S.

Andrew S. wrote:

Lines 959 to 963 are:
if (widget.buffer.end_iter.class == Gtk::TextIter and
tbuffer.start_iter.class == Gtk::TextIter and tbuffer.end_iter.class ==
Gtk::TextIter)
widget.buffer.insert_range(widget.buffer.end_iter, tbuffer.start_iter,
tbuffer.end_iter)
end

Can you provide a complete test program? This will make it easier for
the developers to check the cause.

Thanks!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs