Bug 4086 - NSEvent.AddLocalMonitorForEventsMatchingMask crashes app.
Summary: NSEvent.AddLocalMonitorForEventsMatchingMask crashes app.
Alias: None
Product: MonoMac
Classification: Desktop
Component: Bindings ()
Version: unspecified
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: ---
Assignee: Rolf Bjarne Kvinge [MSFT]
Depends on:
Reported: 2012-03-25 15:10 UTC by steven.orth
Modified: 2012-04-26 09:40 UTC (History)
3 users (show)

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:

Description steven.orth 2012-03-25 15:10:45 UTC
The first event that occurs (matching the mask) when using NSEvent.AddLocalMonitorForEventsMatchingMask crashes the application. Representative crash dump:


  at (wrapper managed-to-native) MonoMac.AppKit.NSApplication.NSApplicationMain (int,string[]) <0xffffffff>
  at MonoMac.AppKit.NSApplication.Main (string[]) <0x00017>
  at SimpleMonoApp.MainClass.Main (string[]) <0x00017>
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <0xffffffff>

Native stacktrace:

	0   SimpleMonoApp                       0x00094efc mono_handle_native_sigsegv + 284
	1   SimpleMonoApp                       0x00004fe8 mono_sigsegv_signal_handler + 248
	2   libsystem_c.dylib                   0x944bc59b _sigtramp + 43
	3   ???                                 0xffffffff 0x0 + 4294967295
	4   AppKit                              0x9176ae93 -[NSApplication sendEvent:] + 96
	5   AppKit                              0x916fd6d5 -[NSApplication run] + 1007
	6   AppKit                              0x91991261 NSApplicationMain + 1054
	7   ???                                 0x03c43ea0 0x0 + 63192736
	8   ???                                 0x03c43de8 0x0 + 63192552
	9   ???                                 0x004a7da0 0x0 + 4881824
	10  ???                                 0x004a7e37 0x0 + 4881975
	11  SimpleMonoApp                       0x0000d282 mono_jit_runtime_invoke + 722
	12  SimpleMonoApp                       0x001a436a mono_runtime_invoke + 170
	13  SimpleMonoApp                       0x001a6f01 mono_runtime_exec_main + 705
	14  SimpleMonoApp                       0x001a6111 mono_runtime_run_main + 929
	15  SimpleMonoApp                       0x00069995 mono_jit_exec + 149
	16  SimpleMonoApp                       0x0006bf13 mono_main + 9587
	17  SimpleMonoApp                       0x00002299 main + 441
	18  SimpleMonoApp                       0x000020a6 start + 54

Debug info from gdb:

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.

Modified source from boilerplate "new mono app" in MonoDevelop (AppDelegate.cs):

using System;
using MonoMac.Foundation;
using MonoMac.AppKit;

namespace SimpleMonoApp
    public partial class AppDelegate : NSApplicationDelegate
        MainWindowController mainWindowController;
        NSObject monitor;
        public AppDelegate ()

        public override void FinishedLaunching (NSObject notification)
            mainWindowController = new MainWindowController ();
            mainWindowController.Window.MakeKeyAndOrderFront (this);
            monitor = NSEvent.AddLocalMonitorForEventsMatchingMask(NSEventMask.AnyEvent, Monitor);

        private static NSEvent Monitor(NSEvent e)
            return e;
Comment 1 Rolf Bjarne Kvinge [MSFT] 2012-04-26 09:40:52 UTC
Fixed in 7e6e619cd (maccore master).