Event problem with gtk_main_iteration_do(1);
Hi
I develop a binding of gtk+ for Squeak an implementation of the Smalltalk language.
For the event handling I use gtk_main_iteration_do(1); which works fine with x11 and mac os x and x11 support but with this version of gtk+ it crashes :
Thread 0:
0 libSystem.B.dylib 0x0046468e __semwait_signal + 10
1 GtkPlugin 0x43168bff gtkDoGtkMainIteration + 123
2 GtkPlugin 0x430ff22f primitiveDoGtkMainIterationWithSemaphore + 76
Thread 1 Crashed:
0 libSystem.B.dylib 0x0053edbe __semwait_signal_nocancel + 10
1 libSystem.B.dylib 0x00530c87 usleep$NOCANCEL$UNIX2003 + 61
2 libSystem.B.dylib 0x0055248b abort + 85
3 squeak 0x0001db06 queryLoadModule + 0 (sqUnixMain.c:715)
4 ??? 0xffffffff 0 + 4294967295
5 libglib-2.0.0.dylib 0x455f9ade g_main_context_check + 626 (gmain.c:2651)
6 libglib-2.0.0.dylib 0x455fa050 g_main_context_iterate + 1104 (gmain.c:2773)
7 libglib-2.0.0.dylib 0x455fa449 g_main_context_iteration + 116 (gmain.c:2839)
8 libgtk-quartz-2.0.0.dylib 0x43b3c274 gtk_main_iteration_do + 46 (gtkmain.c:1274)
9 GtkPlugin 0x43168b5b gtkThreadHandleEvent + 30
10 libSystem.B.dylib 0x0048e6f5 _pthread_start + 321
11 libSystem.B.dylib 0x0048e5b2 thread_start + 34
Any idea of the problem ???
cheers,
Gwenael Casaccio

May be this can solve the
May be this can solve the problem http://mail.gnome.org/archives/gtk-devel-list/2008-September/msg00031.ht... ?
The output kind of looks
The output kind of looks like a problem in your code, since it's just a crash. What does the line
squeak 0x0001db06 queryLoadModule + 0 (sqUnixMain.c:715)
contain?
(If you want to try the mainloop rework, the right patch is here:http://bugzilla.gnome.org/show_bug.cgi?id=550942)
Oups yes sorry for this post
Oups yes sorry for this post :s
but if I only use the gtk_main_iteration_do(1) and don't handle events I've this problem
Thread 1:
0 libSystem.B.dylib 0x0046468e __semwait_signal + 10
1 GtkPlugin 0x1b7dabf5 gtkDoGtkMainIteration + 123
2 GtkPlugin 0x1b771217 primitiveDoGtkMainIterationWithSemaphore + 76
Thread 2 Crashed:
0 libobjc.A.dylib 0x007e7eba _objc_error + 116
1 libobjc.A.dylib 0x007e7ef0 __objc_error + 52
2 libobjc.A.dylib 0x007e68f7 _freedHandler + 58
3 libgdk-quartz-2.0.0.dylib 0x1cdbdbd7 gdk_event_check + 56 (gdkeventloop-quartz.c:84)
4 libglib-2.0.0.dylib 0x1dcb4ade g_main_context_check + 626 (gmain.c:2651)
5 libglib-2.0.0.dylib 0x1dcb5050 g_main_context_iterate + 1104 (gmain.c:2773)
6 libglib-2.0.0.dylib 0x1dcb5449 g_main_context_iteration + 116 (gmain.c:2839)
7 libgtk-quartz-2.0.0.dylib 0x1c1e2300 gtk_main_iteration_do + 46 (gtkmain.c:1274)
8 GtkPlugin 0x1b7dab43 gtkThreadHandleEvent + 30
9 libSystem.B.dylib 0x0048e6f5 _pthread_start + 321
10 libSystem.B.dylib 0x0048e5b2 thread_start + 34
Are you using threads in
Are you using threads in your code and using gtk/gdk APIs without enabling gdk threads and using the gdk locks, perhaps?
Here is the code void*
Here is the code
void* gtkThreadHandleEvent(void* ptr)
{
gdk_threads_enter();
gtk_main_iteration_do(1);
gdk_threads_leave();
interpreterProxy->signalSemaphoreWithIndex((int)ptr);
pthread_exit(NULL);
}
void gtkDoGtkMainIteration(int semaIndex)
{
pthread_t thread;
void* ret;
if (pthread_create(&thread, NULL, gtkThreadHandleEvent, (void*)semaIndex) < 0) {
printf("[SqueakGTK] gtkDoGtkMainIteration thread create failed\n");
gtk_main_iteration_do(0);
interpreterProxy->signalSemaphoreWithIndex(semaIndex);
return ;
}
pthread_join(thread, &ret);
}
OK, that looks right (if
OK, that looks right (if gtkDoGtkMainIteration is called with the lock held). The general approach looks a bit strange to me though, maybe you should check how other bindings do this, like python or ruby?
In the smalltalk language we
In the smalltalk language we have process, If I call directly gtk_main() I won't return to the vm sidem so we create a background process for the gtk_main_iteration_do(1) the current code and we have an other process that handle the gtk events (the callbacks). I suppose in python and ruby they don't use threads for gtk_main_iteration_do(1).
By the way I've changed gtk_main_iteration_do(1) with gtk_main() and again I don't process the callbacks, I can see the windows sometimes it crashes in gsignal.c line 711. But if I click on a menu I don't see the submenu I don't know why because there are no callbacks attached to this menu ???
I can resize the window but if I click on a tab or on a text editor the cursor doesn't move, to be clear nothing happens ??
I'm sorry I hope I don't bore you :s
Gwenael Casaccio
Python and other languages
Python and other languages should have similar issues but they don't solve it with a thread. I meant that maybe you could look at how they solve it?