[Gtk-sharp-list] Key Snooper

Mathew McKernan MatMcKernan at rauland.com.au
Thu Dec 7 23:32:03 EST 2006

Hi All,
I am working with the GTK# libraries at present, and I am trying to
initalise a key snooper. I successfully can call the snooper install
etc. However, when it looks like the snooper is being garbage collected
or similar before callback.
Mono ends up bailing out with a SIGSEGV, whereas windows exceptions with
a "CallbackOnCollectedDelegate".
Here is a stack trace from mono:

Got a SIGSEGV while executing native code. This usually indicates

a fatal error in the mono runtime or one of the native libraries 

used by your application.



at (wrapper managed-to-native) Gtk.Application.gtk_main () <0x00004>
at (wrapper managed-to-native) Gtk.Application.gtk_main () <0xffffffff>
at Gtk.Application.Run () <0x00007>
at xxx.loadClient () <0x000e6>
at xxx.Program.Main (string[]) <0x0008e>
at (wrapper runtime-invoke) System.Object.runtime_invoke_void_string[]
(object,intptr,intptr,intptr) <0xffffffff>
Native stacktrace:
mono [0x813f45c]
mono [0x812a028]
/usr/lib/libgtk-x11-2.0.so.0(gtk_main_do_event+0x24d) [0xb712a9dd]
/usr/lib/libgdk-x11-2.0.so.0 [0xb6fb85bf]
/usr/lib/libglib-2.0.so.0 [0xb7ed0603]
/usr/lib/libglib-2.0.so.0(g_main_context_dispatch+0x99) [0xb7ed16a9]
/usr/lib/libglib-2.0.so.0 [0xb7ed19f6]
/usr/lib/libglib-2.0.so.0(g_main_loop_run+0x160) [0xb7ed1f50]
/usr/lib/libgtk-x11-2.0.so.0(gtk_main+0xbb) [0xb712a25b]
mono [0x8129ed2]
mono(mono_runtime_invoke+0x1c) [0x808836c]
mono(mono_runtime_exec_main+0x52) [0x8089262]
mono(mono_runtime_run_main+0x1bb) [0x8088f3b]
mono [0x80584d0]
mono(mono_main+0x770) [0x8058dd0]
mono [0x80578f9]
/lib/tls/libc.so.6(__libc_start_main+0xdb) [0xb7d60fcb]
mono [0x8057831]

Any ideas on what the problem is here? The code I used for the delegate
is below:

public class xxx {
	private uint gtkSnooperKey;
      private Gtk.KeySnoopFunc keyPressFunction;

	private void activateSnooper() {
		keyPressFunction = new
            gtkSnooperKey = Gtk.Key.SnooperInstall(keyPressFunction);

	public int snoopInputEvent(Gtk.Widget w, Gdk.EventKey args) {
            if (args.Type == Gdk.EventType.KeyPress) {
                Console.WriteLine("Got a keypress event");

Thanks for your help guys.



More information about the Gtk-sharp-list mailing list