Bug 1341 - NSEvent.AddGlobalMonitorForEventsMatchingMask crashes app.
Summary: NSEvent.AddGlobalMonitorForEventsMatchingMask crashes app.
Status: RESOLVED FIXED
Alias: None
Product: MonoMac
Classification: Desktop
Component: Bindings ()
Version: GIT
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2011-10-07 11:17 UTC by Dimitris Tavlikos
Modified: 2012-03-07 00:40 UTC (History)
5 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Dimitris Tavlikos 2011-10-07 11:17:31 UTC
Calling the static method NSEvent.AddGlobalMonitorForEventsMatchingMask method causes a crash:


Stacktrace:

  at (wrapper managed-to-native) MonoMac.ObjCRuntime.Messaging.IntPtr_objc_msgSend_UInt32_IntPtr (intptr,intptr,uint,intptr) <IL 0x00028, 0xffffffff>
  at MonoMac.AppKit.NSEvent.AddGlobalMonitorForEventsMatchingMask (MonoMac.AppKit.NSEventMask,MonoMac.AppKit.GlobalEventHandler) [0x00029] in /Users/mrmojo/Projects/Shared/github/monomac/src/AppKit/NSEvent.g.cs:230
  at KeyCapture.MainWindowController.WindowDidLoad () [0x00006] in /Users/mrmojo/Projects/MonoMac/KeyCapture/KeyCapture/MainWindowController.cs:56
  at (wrapper dynamic-method) object.[KeyCapture.MainWindowController.Void WindowDidLoad()] (MonoMac.Foundation.NSObject,MonoMac.ObjCRuntime.Selector) <IL 0x0000b, 0x0004c>
  at (wrapper native-to-managed) object.[KeyCapture.MainWindowController.Void WindowDidLoad()] (MonoMac.Foundation.NSObject,MonoMac.ObjCRuntime.Selector) <IL 0x00081, 0xffffffff>
  at (wrapper managed-to-native) MonoMac.ObjCRuntime.Messaging.IntPtr_objc_msgSendSuper (intptr,intptr) <IL 0x00026, 0xffffffff>
  at MonoMac.AppKit.NSWindowController.get_Window () [0x0002b] in /Users/mrmojo/Projects/Shared/github/monomac/src/AppKit/NSWindowController.g.cs:367
  at KeyCapture.MainWindowController.get_Window () [0x00000] in /Users/mrmojo/Projects/MonoMac/KeyCapture/KeyCapture/MainWindowController.cs:46
  at KeyCapture.AppDelegate.FinishedLaunching (MonoMac.Foundation.NSObject) [0x0000b] in /Users/mrmojo/Projects/MonoMac/KeyCapture/KeyCapture/AppDelegate.cs:20
  at (wrapper dynamic-method) object.[KeyCapture.AppDelegate.Void FinishedLaunching(MonoMac.Foundation.NSObject)] (MonoMac.Foundation.NSObject,MonoMac.ObjCRuntime.Selector,MonoMac.Foundation.NSObject) <IL 0x00011, 0x00050>
  at (wrapper native-to-managed) object.[KeyCapture.AppDelegate.Void FinishedLaunching(MonoMac.Foundation.NSObject)] (MonoMac.Foundation.NSObject,MonoMac.ObjCRuntime.Selector,MonoMac.Foundation.NSObject) <IL 0x000b6, 0xffffffff>
  at (wrapper managed-to-native) MonoMac.AppKit.NSApplication.NSApplicationMain (int,string[]) <IL 0x0009d, 0xffffffff>
  at MonoMac.AppKit.NSApplication.Main (string[]) [0x00000] in /Users/mrmojo/Projects/Shared/github/monomac/src/AppKit/NSApplication.cs:74
  at KeyCapture.MainClass.Main (string[]) [0x00005] in /Users/mrmojo/Projects/MonoMac/KeyCapture/KeyCapture/Main.cs:14
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <IL 0x00050, 0xffffffff>

Native stacktrace:

	0   KeyCapture                          0x000b90c6 mono_handle_native_sigsegv + 422
	1   KeyCapture                          0x00003f3e mono_sigsegv_signal_handler + 334
	2   libsystem_c.dylib                   0x9169b59b _sigtramp + 43
	3   ???                                 0xffffffff 0x0 + 4294967295
	4   AppKit                              0x92405edb -[_NSGlobalEventObserver initMatchingEvents:handler:] + 69
	5   AppKit                              0x9240c9ea +[NSEvent addGlobalMonitorForEventsMatchingMask:handler:] + 81
	6   ???                                 0x03d1ac92 0x0 + 64072850
	7   ???                                 0x03d1a328 0x0 + 64070440
	8   ???                                 0x03d1961c 0x0 + 64067100
	9   ???                                 0x03d02835 0x0 + 63973429
	10  ???                                 0x03d10684 0x0 + 64030340
	11  AppKit                              0x921f6e1e -[NSWindowController _windowDidLoad] + 579
	12  AppKit                              0x921ee116 -[NSWindowController window] + 121
	13  ???                                 0x03d125a3 0x0 + 64038307
	14  ???                                 0x03d16608 0x0 + 64054792
	15  ???                                 0x03d164e4 0x0 + 64054500
	16  ???                                 0x03d14638 0x0 + 64046648
	17  ???                                 0x03d02ad1 0x0 + 63974097
	18  ???                                 0x03d10d8c 0x0 + 64032140
	19  Foundation                          0x90a7151d __-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke_1 + 49
	20  CoreFoundation                      0x99621843 ___CFXNotificationPost_block_invoke_1 + 275
	21  CoreFoundation                      0x995ec658 _CFXNotificationPost + 2776
	22  Foundation                          0x90a5c70a -[NSNotificationCenter postNotificationName:object:userInfo:] + 92
	23  AppKit                              0x91ff04cc -[NSApplication _postDidFinishNotification] + 259
	24  AppKit                              0x91ff01c2 -[NSApplication _sendFinishLaunchingNotification] + 84
	25  AppKit                              0x91feeda4 -[NSApplication(NSAppleEventHandling) _handleAEOpenEvent:] + 277
	26  AppKit                              0x91feeaba -[NSApplication(NSAppleEventHandling) _handleCoreEvent:withReplyEvent:] + 377
	27  CoreFoundation                      0x99639db8 -[NSObject performSelector:withObject:withObject:] + 72
	28  Foundation                          0x90a967e6 __-[NSAppleEventManager setEventHandler:andSelector:forEventClass:andEventID:]_block_invoke_1 + 121
	29  Foundation                          0x90a95599 -[NSAppleEventManager dispatchRawAppleEvent:withRawReply:handlerRefCon:] + 476
	30  Foundation                          0x90a9536d _NSAppleEventManagerGenericHandler + 234
	31  AE                                  0x93bcdf1d _Z20aeDispatchAppleEventPK6AEDescPS_mPh + 202
	32  AE                                  0x93bb7a4b _ZL25dispatchEventAndSendReplyPK6AEDescPS_ + 43
	33  AE                                  0x93bb7938 aeProcessAppleEvent + 253
	34  HIToolbox                           0x92c0df72 AEProcessAppleEvent + 103
	35  AppKit                              0x91febb5b _DPSNextEvent + 1301
	36  AppKit                              0x91feb159 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 113
	37  AppKit                              0x91fe74cb -[NSApplication run] + 904
	38  AppKit                              0x9227ab54 NSApplicationMain + 1054
	39  ???                                 0x03d1128e 0x0 + 64033422
	40  ???                                 0x03d1108c 0x0 + 64032908
	41  ???                                 0x004bcff8 0x0 + 4968440
	42  ???                                 0x004bd156 0x0 + 4968790
	43  KeyCapture                          0x0000fa34 mono_jit_runtime_invoke + 164
	44  KeyCapture                          0x001be768 mono_runtime_invoke + 137
	45  KeyCapture                          0x001c0f6a mono_runtime_exec_main + 669
	46  KeyCapture                          0x001c02a4 mono_runtime_run_main + 843
	47  KeyCapture                          0x000888cb mono_main + 7755
	48  KeyCapture                          0x00001ed6 start + 54

Debug info from gdb:

/tmp/mono-gdb-commands.V0uQLc:1: Error in sourced command file:
unable to debug self

=================================================================
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.
=================================================================

To reproduce, just add the following call:

NSEvent.AddGlobalMonitorForEventsMatchingMask(NSEventMask.KeyDown, delegate(NSEvent evt) {

Console.WriteLine("Whatever");

});
Comment 1 myl 2011-10-25 13:47:01 UTC
Vote for a fix.
Comment 2 Sune Beck 2012-02-21 19:37:40 UTC
I'm directly affected by this bug, and will hereby place my vote as well! Keep up the good work, devs!
Comment 3 Anders 2012-02-27 05:16:09 UTC
Hi Miguel and the Xamarin team,

Thanks so much for an amazing job. Its a pleasure working with your tools.

I would really appreciate a fix for this!

Anders
Comment 4 myl 2012-02-28 06:13:31 UTC
Somebody fixed this without marking it fixed! Awesome.
Comment 5 Miguel de Icaza [MSFT] 2012-03-07 00:40:33 UTC
Glad to hear that it was fixed, but I would like to have a test case to ensure we do not regress in the future.

This was probably fixed by Rolf's new assembly language trampolines