Losing GtkTextBuffer when threading



Hello,

My project is a simple telnet terminal designed to help me understand GTK+ with network programming.

I have a struct called networktype:
typedef struct networktype{
   ...
   GtkTextBuffer *output_buffer;
   ..
} networktype;

I have a function:
void append_to_buffer( GtkTextBuffer *output_buffer, char *text ){
   GtkTextIter output_end;
gtk_text_buffer_get_end_iter( output_buffer, &output_end ); gtk_text_buffer_insert( output_buffer, &output_end, text, -1 );
}

another function:
int net_init( networktype *net, GtkTextBuffer *buf ){
   net->output_buffer = buf;
   append_to_buffer( net->output_buffer, "Initilizing Network\n");
   ...
}

and a thread:
void *net_thread( void *args ){
... append_to_buffer( net->output_buffer, "Getting host by name\n");
}



in the main function I've done everything right, as far as I know:
   g_thread_init( NULL );
   gdk_threads_init();
   gdk_threads_enter();
   net_init( &net, txtoutput_buffer);
   pthread_create( &net->thread, NULL, net_thread, &net );

Now, the append_buffer function works inside of the function net_init(); but it fails when I try to use it inside the thread, even after the feild net->output_buffer has been properly initialized.

Here is the error:
(simpleterm.exe:2772): Gtk-CRITICAL **: gtk_text_buffer_get_end_iter: assertion
`GTK_IS_TEXT_BUFFER (buffer)' failed

(simpleterm.exe:2772): Gtk-CRITICAL **: gtk_text_buffer_insert: assertion `GTK_I
S_TEXT_BUFFER (buffer)' failed



What's going on here?





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]