cocoa icon indicating copy to clipboard operation
cocoa copied to clipboard

Crash using NSDistributedNotificationCenter

Open dnicolson opened this issue 8 years ago • 0 comments

This is perhaps an issue for the https://github.com/ffi/ffi project, I was unable to successfully recreate the code only working with the ffi gem though.

The issue affects at least macOS 10.12.3 and all versions of Ruby.

The following code results in the ruby processing crashing:

require 'cocoa'

class NotificationHandler < Cocoa::NSObject
  def initialize
    c = Cocoa::NSDistributedNotificationCenter.defaultCenter
    c.addObserver(self, selector: 'notification:', name: 'com.apple.iTunes.playerInfo', object: nil)
  end

  def notification(n)
    p n
  end
end

NotificationHandler.new
Cocoa::NSApplication.sharedApplication.run

Here is an excerpt of the crash:

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   com.apple.CoreFoundation      	0x00007fff8c1b14bb __CFXNotificationRegisterObserver + 1611
1   com.apple.CoreFoundation      	0x00007fff8c0b679d _CFXNotificationRegisterObserver + 29
2   com.apple.Foundation          	0x00007fff8dafcfc5 -[NSDistributedNotificationCenter addObserver:selector:name:object:suspensionBehavior:] + 177
3   com.apple.Foundation          	0x00007fff8db0643f -[NSDistributedNotificationCenter addObserver:selector:name:object:] + 29
4   libffi.dylib                  	0x00007fffa06acf1c ffi_call_unix64 + 76
5   libffi.dylib                  	0x00007fffa06ad7b1 ffi_call + 937
6   ffi_c.bundle                  	0x000000010493b1b5 variadic_invoke + 869

dnicolson avatar Jan 31 '17 19:01 dnicolson