GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sun Nov 23, 2014 8:37 am

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: GtkTextBuffer Iterator problem
PostPosted: Sat May 19, 2007 5:07 am 
Offline

Joined: Fri May 18, 2007 2:19 pm
Posts: 2
hello gtk-gurus,

I have a strange problem using the GtkTextBuffer widget. I want to display some text which is provided by two threads in a GtkTextView. The new text simply should be appended to the existing one so that I get a kind of logfile.

Therefore I have created a function called "logging (char* txt_p)" which is called in every thread. This function creates a new text buffer GtkTextBuffer, fetches the current text of the GtkTextView widget, sets an iterator at the end of the text and inserts the new string. Finally, the text buffer is written onto the GtkTextView widget. To make the function thread-safe I use pthread_mutex_t.

Now I have the problem, that the application crashes with the following error:

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

Can anyone help me pleaze??

mike


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 22, 2007 12:00 am 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
Could you post the code from the function? We can't really tell where you're having the problem without some code ...

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 22, 2007 5:26 am 
Offline

Joined: Fri May 18, 2007 2:19 pm
Posts: 2
Ok, sorry!
The function which adds some text to the textbuffer / textview is the following:

void logging_add (char* text) {

GtkTextBuffer* text_p;
GtkTextIter text_end;
GtkTextView* view_p;

/* Create a new text buffer */
text_p = gtk_text_buffer_new (NULL);

/* Get the text view widget */
view_p = (GtkTextView*)glade_xml_get_widget (xml_p, "txt_logging");

/* Get the current text from the text view */
text_p = gtk_text_view_get_buffer (view_p);

/* Get the last element from the current text buffer */
gtk_text_buffer_get_end_iter (text_p, &text_end);

/* Insert the new text into the text buffer */
gtk_text_buffer_insert (text_p, &text_end, text, -1);

gtk_text_view_set_buffer (view_p, text_p);
}

Always when some data has been arrived, the logging function is called using a critical section for getting the thread-safety:

pthread_mutex_lock (&cs_mutex);
logging_add ("-> ");
logging_add (buffer_head_ptr (&recv_buffer));
logging_add ("\n");
pthread_mutex_unlock (&cs_mutex);

I hope this helps,
mike[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 22, 2007 1:35 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
Well, there is no need to call gtk_text_buffer_new(). An initial text buffer is created for you by the GtkTextView, nor is there any need to set the buffer since you retrieved the one that is associated with the GtkTextView.

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group