Archived

This topic is now archived and is closed to further replies.

stefu

multithreading gtk

Recommended Posts

Hello! I''m writing multithreding network game on gtk2 and got this problem: Xlib: unexpected async reply (sequence 0x26ac)! I don''t know yet how to solve this. I found that it occurs when I try to write to textbuffer from another thread (network receiving thread). I have to kill app then. I already tried using gdk_threads_enter/leave(). It didn''t help. Then I noticed that need to call first g_thread_init(NULL) and gdk_threads_init() but segmentation fault occurse even if I link with libgthreads I try to find a solution, but if anyone knows solution I''d be very pleased

Share this post


Link to post
Share on other sites
The problem actually is not there if I remove these lines:

GtkAdjustment *vadj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(scroll_view));
gtk_adjustment_set_value(vadj, vadj->upper); // <-- This caused async error
}


Those just scroll text-view down to view text that was appended at end of text-buffer. Is there other ways or automatic ways to scroll down?

Share this post


Link to post
Share on other sites
Hi, hope someone hears

Here's the simples gtk app possible with thread safety:

    
#include <gtk/gtk.h>

int main (int argc, char *argv[])
{
GtkWidget *window;

g_thread_init (NULL);
gdk_threads_init();
gtk_init (&argc, &argv);

window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_show(window);

gdk_threads_enter();
gtk_main();
gdk_threads_leave();

return 0;
}


Then I compile it:

g++ gtest.cpp -o gtest `pkg-config --libs gtk+-2.0` `pkg-config --cflags gtk+-2.0` -lgthread


And I'm getting Segmentation fault as soon as I run it! What am I doing wrong?


[edited by - stefu on October 20, 2002 4:00:14 PM]

Share this post


Link to post
Share on other sites