Crash with objc_msgSend() selector name: countByEnumeratingWithState:objects:count: - cocoa

My cocoa app occasionally crashes with the above specific information. I'm sure that it's due to NSTableView display in my app but I can't figure out what's wrong. The crash report is as below. Can anyone tell what's going on?
Application Specific Information:
objc_msgSend() selector name: countByEnumeratingWithState:objects:count:
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libobjc.A.dylib 0x00007fff8847a0dd objc_msgSend + 29
1 com.apple.AppKit 0x00007fff8ae1a44a -[NSView _displayRectIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:] + 6008
2 com.apple.AppKit 0x00007fff8add12be -[NSView displayIfNeeded] + 1876
3 com.apple.AppKit 0x00007fff8add0b19 -[NSWindow displayIfNeeded] + 236
4 com.apple.AppKit 0x00007fff8add0782 _handleWindowNeedsDisplayOrLayoutOrUpdateConstraints + 936
5 com.apple.AppKit 0x00007fff8b506191 __83-[NSWindow _postWindowNeedsDisplayOrLayoutOrUpdateConstraintsUnlessPostingDisabled]_block_invoke1540 + 46
6 com.apple.CoreFoundation 0x00007fff8dd32127 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
7 com.apple.CoreFoundation 0x00007fff8dd32080 __CFRunLoopDoObservers + 368
8 com.apple.CoreFoundation 0x00007fff8dd24188 __CFRunLoopRun + 872
9 com.apple.CoreFoundation 0x00007fff8dd23bd8 CFRunLoopRunSpecific + 296
10 com.apple.HIToolbox 0x00007fff950db56f RunCurrentEventLoopInMode + 235
11 com.apple.HIToolbox 0x00007fff950db2ea ReceiveNextEventCommon + 431
12 com.apple.HIToolbox 0x00007fff950db12b _BlockUntilNextEventMatchingListInModeWithFilter + 71
13 com.apple.AppKit 0x00007fff8adcd9bb _DPSNextEvent + 978
14 com.apple.AppKit 0x00007fff8adccf68 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 346
15 com.apple.AppKit 0x00007fff8adc2bf3 -[NSApplication run] + 594
16 com.apple.AppKit 0x00007fff8ad3f354 NSApplicationMain + 1832
17 libdyld.dylib 0x00007fff8980e5c9 start + 1

Related

Xcode 7 doesn't run more: Bad Access

I was working with Xcode last night, in morning I relaunch the XCode and it crash, an error appears.
I tried to delete the Preferences, cache, reinstall all... nothing.
But if I run Xcode from terminal with root privilege, it runs but Simulator doesn't work properly...
Error dump:
Exception Type: EXC_BAD_ACCESS (SIGBUS) Exception Codes:
0x000000000000000a, 0x000000010e8ac000 Exception Note:
EXC_CORPSE_NOTIFY
VM Regions Near 0x10e8ac000:
__LINKEDIT 000000010e83e000-000000010e83f000 [ 4K] rw-/rwx SM=NUL
/Applications/Xcode.app/Contents/Developer/Library/PrivateFrameworks/CoreSimulator.framework/Versions/A/CoreSimulator
--> mapped file 000000010e83f000-000000010e9e3000 [ 1680K] r--/rwx SM=COW
MALLOC_LARGE 000000010e9e3000-000000010ebe9000 [ 2072K] rw-/rwx SM=PRV
Application Specific Information: ProductBuildVersion: 7B1005
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread 0
com.apple.CoreFoundation 0x00007fff99b9852b
CFStringCreateImmutableFunnel3 + 795 1 com.apple.CoreFoundation 0x00007fff99ba844b CFStringCreateWithBytes + 59 2
com.apple.CoreFoundation 0x00007fff99bd4ff9
__CFBinaryPlistCreateObjectFiltered + 7273 3 com.apple.CoreFoundation 0x00007fff99bd4c82
__CFBinaryPlistCreateObjectFiltered + 6386 4 com.apple.CoreFoundation 0x00007fff99bd4c82
__CFBinaryPlistCreateObjectFiltered + 6386 5 com.apple.CoreFoundation 0x00007fff99bd4c82
__CFBinaryPlistCreateObjectFiltered + 6386 6 com.apple.CoreFoundation 0x00007fff99bd4c82
__CFBinaryPlistCreateObjectFiltered + 6386 7 com.apple.CoreFoundation 0x00007fff99bd4347
__CFBinaryPlistCreateObjectFiltered + 4023 8 com.apple.CoreFoundation 0x00007fff99bd4c82
__CFBinaryPlistCreateObjectFiltered + 6386 9 com.apple.CoreFoundation 0x00007fff99bb8427
__CFTryParseBinaryPlist + 215 10 com.apple.CoreFoundation 0x00007fff99bb7ca9 _CFPropertyListCreateWithData + 89 11
com.apple.CoreFoundation 0x00007fff99bb7bad
CFPropertyListCreateWithData + 93 12 com.apple.Foundation
0x00007fff8b8400d7 +[NSPropertyListSerialization
propertyListWithData:options:format:error:] + 94 13
com.apple.dt.DVTFoundation 0x00000001066a81f3 -[DVTPlugInManager
_loadPlugInCache:] + 260 14 com.apple.dt.DVTFoundation 0x00000001066a34a5 -[DVTPlugInManager _scanForPlugIns:] + 3304 15
com.apple.dt.IDEFoundation 0x00000001073e25e9 IDEInitialize + 3250
16 com.apple.dt.IDEKit 0x0000000107adf2fc
-[IDEApplicationController applicationWillFinishLaunching:] + 708 17 com.apple.CoreFoundation 0x00007fff99c33c9c
__CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER + 12 18 com.apple.CoreFoundation 0x00007fff99c33c2f
___CFXRegistrationPost_block_invoke + 63 19 com.apple.CoreFoundation 0x00007fff99c33ba7 _CFXRegistrationPost + 407 20
com.apple.CoreFoundation 0x00007fff99c33912
___CFXNotificationPost_block_invoke + 50 21 com.apple.CoreFoundation 0x00007fff99bf06d2 -[_CFXNotificationRegistrar
find:object:observer:enumerator:] + 1922 22 com.apple.CoreFoundation
0x00007fff99bef925 _CFXNotificationPost + 693 23
com.apple.Foundation 0x00007fff8b82f0fa
-[NSNotificationCenter postNotificationName:object:userInfo:] + 66 24 com.apple.dt.DVTFoundation 0x0000000106883d35
-[NSNotificationCenter(DVTNSNotificationCenterAdditions) _dvt_postNotificationName:object:userInfo:] + 698 25 com.apple.AppKit 0x00007fff9249d022 -[NSApplication finishLaunching] + 354 26
com.apple.dt.DVTKit 0x0000000106e83494 -[DVTApplication
finishLaunching] + 149 27 com.apple.AppKit
0x00007fff9249cb65 -[NSApplication run] + 231 28 com.apple.AppKit
0x00007fff92465fbe NSApplicationMain + 1176 29 libdyld.dylib
0x00007fff8b5eb5ad start + 1

'Heap corruption detected' crashes in OS X app

I'm seeing quite a few problems with the latest release of our software.
I'm getting customer complaints about crashes. Unfortunately though, I can't get any information from the crash reports. Here is one I receive the most:
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Application Specific Information:
abort() called
*** error for object 0x610000039720: Heap corruption detected, free list canary is damaged
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libsystem_kernel.dylib 0x000000010444c866 __pthread_kill + 10
1 libsystem_pthread.dylib 0x000000010455735c pthread_kill + 92
2 libsystem_c.dylib 0x0000000104380b1a abort + 125
3 libsystem_malloc.dylib 0x00000001044ccbee nanozone_error + 486
4 libsystem_malloc.dylib 0x00000001044ccdb0 _nano_malloc_check_clear + 445
5 libsystem_malloc.dylib 0x00000001044cb6b0 nano_malloc + 35
6 libsystem_malloc.dylib 0x00000001044c9868 malloc_zone_malloc + 71
7 com.apple.CoreFoundation 0x0000000103e63fed _CFRuntimeCreateInstance + 253
8 com.apple.CoreGraphics 0x0000000104a45d70 CGTypeCreateInstance + 79
9 com.apple.CoreGraphics 0x0000000104a45c25 region_create_with_shape + 37
10 com.apple.CoreGraphics 0x0000000104a6c0d1 CGSNewEmptyRegion + 24
11 com.apple.AppKit 0x0000000100570ae2 -[NSView _regionForOpaqueDescendants:forMove:] + 4090
12 com.apple.AppKit 0x00000001005706eb -[NSView _regionForOpaqueDescendants:forMove:] + 3075
13 com.apple.AppKit 0x00000001005706eb -[NSView _regionForOpaqueDescendants:forMove:] + 3075
14 com.apple.AppKit 0x00000001005706eb -[NSView _regionForOpaqueDescendants:forMove:] + 3075
15 com.apple.AppKit 0x00000001005706eb -[NSView _regionForOpaqueDescendants:forMove:] + 3075
16 com.apple.AppKit 0x00000001005706eb -[NSView _regionForOpaqueDescendants:forMove:] + 3075
17 com.apple.AppKit 0x000000010069b59d -[NSView _drawRect:clip:] + 1010
18 com.apple.AppKit 0x000000010069903c -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 3199
19 com.apple.AppKit 0x0000000100699bc4 -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 6151
20 com.apple.AppKit 0x0000000100699bc4 -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 6151
21 com.apple.AppKit 0x0000000100697eb1 -[NSThemeFrame _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 314
22 com.apple.AppKit 0x0000000100694e9f -[NSView _displayRectIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:] + 2828
23 com.apple.AppKit 0x00000001006742da -[NSView displayIfNeeded] + 1680
24 com.apple.AppKit 0x00000001006d974e _handleWindowNeedsDisplayOrLayoutOrUpdateConstraints + 884
25 com.apple.AppKit 0x0000000100caf061 __83-[NSWindow _postWindowNeedsDisplayOrLayoutOrUpdateConstraintsUnlessPostingDisabled]_block_invoke1331 + 46
26 com.apple.CoreFoundation 0x0000000103edfd67 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
27 com.apple.CoreFoundation 0x0000000103edfcd7 __CFRunLoopDoObservers + 391
28 com.apple.CoreFoundation 0x0000000103ed13b8 __CFRunLoopRun + 776
29 com.apple.CoreFoundation 0x0000000103ed0e75 CFRunLoopRunSpecific + 309
30 com.apple.HIToolbox 0x0000000109bd2a0d RunCurrentEventLoopInMode + 226
31 com.apple.HIToolbox 0x0000000109bd27b7 ReceiveNextEventCommon + 479
32 com.apple.HIToolbox 0x0000000109bd25bc _BlockUntilNextEventMatchingListInModeWithFilter + 65
33 com.apple.AppKit 0x000000010053d24e _DPSNextEvent + 1434
34 com.apple.AppKit 0x000000010053c89b -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 122
35 com.apple.AppKit 0x000000010053099c -[NSApplication run] + 553
36 com.apple.AppKit 0x000000010051b783 NSApplicationMain + 940
37 libdyld.dylib 0x00000001042b65fd start + 1
The odd thing is that in the piece of code that produces the crash, the application is not doing anything. It's almost completely idle sitting there and waiting. This really makes it look like a memory corruption issue.
I've tried and profiled with Instruments to find any leaks. I also tried Xcode 7's new address sanitizer. To no avail.
Can anyone please give me a hint on what I could try to fix the issue?
I'm pretty sure that the issue only appears with release builds but I still couldn't pin down the reason of the crashes.

Adding a notification observer in swift

There are other stackoverflow questions concerning this, but my the solutions mentioned do not appear to apply to this problem. I have a NSTextField and I want to be notified everytime the text changes in the field. I have a NSViewController controlling the view that contains the NSTextField and it will be the observer.
My class simply looks like this:
import Cocoa
class ADDViewController: NSViewController
{
#IBOutlet weak var fieldText: NSTextField!
func fieldTextChanged( notification: NSNotification )
{
println( "fieldTextChanged" )
}
override var nibName: String?
{
return "ADDViewController"
}
override func viewDidLoad()
{
super.viewDidLoad()
NSNotificationCenter.defaultCenter().addObserver( self, selector: "fieldTextChanged:" as Selector, name: NSControlTextDidChangeNotification, object: fieldText )
}
}
The notification is being added and is firing. When I type a character into the field, I see in the stack trace:
#0 0x00007fff905880e9 in objc_msgSend ()
#1 0x00007fff8f27c45c in __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ ()
#2 0x00007fff8f16c634 in _CFXNotificationPost ()
#3 0x00007fff8fcf0aa1 in -[NSNotificationCenter postNotificationName:object:userInfo:] ()
#4 0x00007fff8f27c45c in __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ ()
#5 0x00007fff8f16c634 in _CFXNotificationPost ()
#6 0x00007fff8fcf0aa1 in -[NSNotificationCenter postNotificationName:object:userInfo:] ()
#7 0x00007fff8ab3deb1 in -[NSTextView(NSSharing) didChangeText] ()
right before it crashes. I did try changing the selector to:
#objc func fieldTextChanged( notification: NSNotification )
{
println( "fieldTextChanged" )
}
but, when I do this, it still doesn't work. What I see in the console:
2015-08-23 18:36:32.240 addobserver_test[52788:3477511] -[__NSCFString fieldTextChanged:]: unrecognized selector sent to instance 0x6000000c3720
2015-08-23 18:36:32.240 addobserver_test[52788:3477511] An uncaught exception was raised
2015-08-23 18:36:32.240 addobserver_test[52788:3477511] -[__NSCFString fieldTextChanged:]: unrecognized selector sent to instance 0x6000000c3720
2015-08-23 18:36:32.244 addobserver_test[52788:3477511] (
0 CoreFoundation 0x00007fff8f2c003c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff9059576e objc_exception_throw + 43
2 CoreFoundation 0x00007fff8f2c30ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00007fff8f208e24 ___forwarding___ + 1028
4 CoreFoundation 0x00007fff8f208998 _CF_forwarding_prep_0 + 120
5 CoreFoundation 0x00007fff8f27c45c __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
6 CoreFoundation 0x00007fff8f16c634 _CFXNotificationPost + 3140
7 Foundation 0x00007fff8fcf0aa1 -[NSNotificationCenter postNotificationName:object:userInfo:] + 66
8 CoreFoundation 0x00007fff8f27c45c __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
9 CoreFoundation 0x00007fff8f16c634 _CFXNotificationPost + 3140
10 Foundation 0x00007fff8fcf0aa1 -[NSNotificationCenter postNotificationName:object:userInfo:] + 66
11 AppKit 0x00007fff8ab3deb1 -[NSTextView(NSSharing) didChangeText] + 348
12 AppKit 0x00007fff8ab3b13b -[NSTextView insertText:replacementRange:] + 2827
13 AppKit 0x00007fff8ab3a237 -[NSTextInputContext(NSInputContext_WithCompletion) insertText:replacementRange:completionHandler:] + 98
14 AppKit 0x00007fff8ab3a1ca __55-[NSTextInputContext handleTSMEvent:completionHandler:]_block_invoke_2242 + 127
15 AppKit 0x00007fff8ab3a12d -[NSTextInputContext do_HandleTSMEvent_insertFixLenTextLoop:whileCondition:dispatchWorkEach:afterEachInsertText:continuation:] + 170
16 AppKit 0x00007fff8b0f653e -[NSTextInputContext tryHandleTSMEvent_insertFixLenText_withContext:dispatchCondition:setupForDispatch:nestedWorkaroundCondition:nestedWorkaroundDispatchWork:loopCondition:dispatchWorkEach:afterEachInsertText:continuation:] + 377
17 AppKit 0x00007fff8ab39b76 __55-[NSTextInputContext handleTSMEvent:completionHandler:]_block_invoke174 + 3779
18 AppKit 0x00007fff8ab38bff -[NSTextInputContext(NSInputContext_WithCompletion) hasMarkedTextWithCompletionHandler:] + 76
19 AppKit 0x00007fff8ab38ba0 __55-[NSTextInputContext handleTSMEvent:completionHandler:]_block_invoke_2 + 95
20 AppKit 0x00007fff8ab38b18 -[NSTextInputContext tryHandleTSMEvent_HasMarkedText_withDispatchCondition:dispatchWork:continuation:] + 101
21 AppKit 0x00007fff8ab387d5 -[NSTextInputContext handleTSMEvent:completionHandler:] + 3122
22 AppKit 0x00007fff8ab37b2e _NSTSMEventHandler + 324
23 HIToolbox 0x00007fff8c691b6c _ZL23DispatchEventToHandlersP14EventTargetRecP14OpaqueEventRefP14HandlerCallRec + 1260
24 HIToolbox 0x00007fff8c690fae _ZL30SendEventToEventTargetInternalP14OpaqueEventRefP20OpaqueEventTargetRefP14HandlerCallRec + 386
25 HIToolbox 0x00007fff8c690e22 SendEventToEventTargetWithOptions + 43
26 HIToolbox 0x00007fff8c6f526c SendTSMEvent_WithCompletionHandler + 417
27 HIToolbox 0x00007fff8c6f576c __SendUnicodeTextAEToUnicodeDoc_WithCompletionHandler_block_invoke + 400
28 HIToolbox 0x00007fff8c6f55a6 __SendFilterTextEvent_WithCompletionHandler_block_invoke + 189
29 HIToolbox 0x00007fff8c6f52c0 SendTSMEvent_WithCompletionHandler + 501
30 HIToolbox 0x00007fff8c6f508f SendFilterTextEvent_WithCompletionHandler + 236
31 HIToolbox 0x00007fff8c6f4d51 SendUnicodeTextAEToUnicodeDoc_WithCompletionHandler + 295
32 HIToolbox 0x00007fff8c6f4ae9 __utDeliverTSMEvent_WithCompletionHandler_block_invoke_2 + 296
33 HIToolbox 0x00007fff8c6f4988 __utDeliverTSMEvent_WithCompletionHandler_block_invoke + 437
34 HIToolbox 0x00007fff8c6f47cd TSMKeyEvent_WithCompletionHandler + 701
35 HIToolbox 0x00007fff8c6f44d0 __TSMProcessRawKeyEventWithOptionsAndCompletionHandler_block_invoke_4 + 251
36 HIToolbox 0x00007fff8c6f4386 __TSMProcessRawKeyEventWithOptionsAndCompletionHandler_block_invoke_3 + 330
37 HIToolbox 0x00007fff8c6f4112 __TSMProcessRawKeyEventWithOptionsAndCompletionHandler_block_invoke_2 + 259
38 HIToolbox 0x00007fff8c6f3f25 __TSMProcessRawKeyEventWithOptionsAndCompletionHandler_block_invoke + 251
39 HIToolbox 0x00007fff8c6d876f TSMProcessRawKeyEventWithOptionsAndCompletionHandler + 3068
40 AppKit 0x00007fff8b0fce86 __61-[NSTextInputContext _handleEvent:options:completionHandler:]_block_invoke949 + 131
41 AppKit 0x00007fff8ab36352 -[NSTextInputContext tryTSMProcessRawKeyEvent:dispatchCondition:setupForDispatch:furtherCondition:dispatchWork:continuation:] + 127
42 AppKit 0x00007fff8ab36085 -[NSTextInputContext _handleEvent:options:completionHandler:] + 1266
43 AppKit 0x00007fff8ab35b4e -[NSTextInputContext handleEvent:] + 109
44 AppKit 0x00007fff8ab35a54 -[NSView interpretKeyEvents:] + 207
45 AppKit 0x00007fff8ab3586a -[NSTextView keyDown:] + 695
46 AppKit 0x00007fff8b0250fb -[NSWindow _reallySendEvent:isDelayedEvent:] + 5452
47 AppKit 0x00007fff8a9b6c86 -[NSWindow sendEvent:] + 470
48 AppKit 0x00007fff8a9b38b1 -[NSApplication sendEvent:] + 4199
49 AppKit 0x00007fff8a8dcb68 -[NSApplication run] + 711
50 AppKit 0x00007fff8a859244 NSApplicationMain + 1832
51 addobserver_test 0x00000001000066cd main + 109
52 libdyld.dylib 0x00007fff91e0b5c9 start + 1
53 ??? 0x0000000000000003 0x0 + 3
)
2015-08-23 18:36:32.358 addobserver_test[52788:3477511] -[__NSCFString fieldTextChanged:]: unrecognized selector sent to instance 0x6000000c3720
2015-08-23 18:36:32.358 addobserver_test[52788:3477511] Exception detected while handling key input.
2015-08-23 18:36:32.358 addobserver_test[52788:3477511] -[__NSCFString fieldTextChanged:]: unrecognized selector sent to instance 0x6000000c3720
2015-08-23 18:36:32.361 addobserver_test[52788:3477511] (
0 CoreFoundation 0x00007fff8f2c003c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff9059576e objc_exception_throw + 43
2 CoreFoundation 0x00007fff8f2c30ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00007fff8f208e24 ___forwarding___ + 1028
4 CoreFoundation 0x00007fff8f208998 _CF_forwarding_prep_0 + 120
5 CoreFoundation 0x00007fff8f27c45c __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
6 CoreFoundation 0x00007fff8f16c634 _CFXNotificationPost + 3140
7 Foundation 0x00007fff8fcf0aa1 -[NSNotificationCenter postNotificationName:object:userInfo:] + 66
8 CoreFoundation 0x00007fff8f27c45c __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
9 CoreFoundation 0x00007fff8f16c634 _CFXNotificationPost + 3140
10 Foundation 0x00007fff8fcf0aa1 -[NSNotificationCenter postNotificationName:object:userInfo:] + 66
11 AppKit 0x00007fff8ab3deb1 -[NSTextView(NSSharing) didChangeText] + 348
12 AppKit 0x00007fff8ab3b13b -[NSTextView insertText:replacementRange:] + 2827
13 AppKit 0x00007fff8ab3a237 -[NSTextInputContext(NSInputContext_WithCompletion) insertText:replacementRange:completionHandler:] + 98
14 AppKit 0x00007fff8abf8932 -[NSKeyBindingManager(NSKeyBindingManager_MultiClients) flushTextForClient:] + 178
15 AppKit 0x00007fff8b0fd2ef __61-[NSTextInputContext _handleEvent:options:completionHandler:]_block_invoke972 + 460
16 AppKit 0x00007fff8ab38bff -[NSTextInputContext(NSInputContext_WithCompletion) hasMarkedTextWithCompletionHandler:] + 76
17 AppKit 0x00007fff8ab50d03 __61-[NSTextInputContext _handleEvent:options:completionHandler:]_block_invoke_3 + 95
18 AppKit 0x00007fff8ab49ed8 -[NSTextInputContext tryHandleEvent_HasMarkedText_withDispatchCondition:dispatchWork:continuation:] + 101
19 AppKit 0x00007fff8b0fd074 __61-[NSTextInputContext _handleEvent:options:completionHandler:]_block_invoke960 + 321
20 HIToolbox 0x00007fff8c6f8d4f __TSMProcessRawKeyEventWithOptionsAndCompletionHandler_block_invoke_5 + 70
21 HIToolbox 0x00007fff8c6f52c0 SendTSMEvent_WithCompletionHandler + 501
22 HIToolbox 0x00007fff8c6f576c __SendUnicodeTextAEToUnicodeDoc_WithCompletionHandler_block_invoke + 400
23 HIToolbox 0x00007fff8c6f55a6 __SendFilterTextEvent_WithCompletionHandler_block_invoke + 189
24 HIToolbox 0x00007fff8c6f52c0 SendTSMEvent_WithCompletionHandler + 501
25 HIToolbox 0x00007fff8c6f508f SendFilterTextEvent_WithCompletionHandler + 236
26 HIToolbox 0x00007fff8c6f4d51 SendUnicodeTextAEToUnicodeDoc_WithCompletionHandler + 295
27 HIToolbox 0x00007fff8c6f4ae9 __utDeliverTSMEvent_WithCompletionHandler_block_invoke_2 + 296
28 HIToolbox 0x00007fff8c6f4988 __utDeliverTSMEvent_WithCompletionHandler_block_invoke + 437
29 HIToolbox 0x00007fff8c6f47cd TSMKeyEvent_WithCompletionHandler + 701
30 HIToolbox 0x00007fff8c6f44d0 __TSMProcessRawKeyEventWithOptionsAndCompletionHandler_block_invoke_4 + 251
31 HIToolbox 0x00007fff8c6f4386 __TSMProcessRawKeyEventWithOptionsAndCompletionHandler_block_invoke_3 + 330
32 HIToolbox 0x00007fff8c6f4112 __TSMProcessRawKeyEventWithOptionsAndCompletionHandler_block_invoke_2 + 259
33 HIToolbox 0x00007fff8c6f3f25 __TSMProcessRawKeyEventWithOptionsAndCompletionHandler_block_invoke + 251
34 HIToolbox 0x00007fff8c6d876f TSMProcessRawKeyEventWithOptionsAndCompletionHandler + 3068
35 AppKit 0x00007fff8b0fce86 __61-[NSTextInputContext _handleEvent:options:completionHandler:]_block_invoke949 + 131
36 AppKit 0x00007fff8ab36352 -[NSTextInputContext tryTSMProcessRawKeyEvent:dispatchCondition:setupForDispatch:furtherCondition:dispatchWork:continuation:] + 127
37 AppKit 0x00007fff8ab36085 -[NSTextInputContext _handleEvent:options:completionHandler:] + 1266
38 AppKit 0x00007fff8ab35b4e -[NSTextInputContext handleEvent:] + 109
39 AppKit 0x00007fff8ab35a54 -[NSView interpretKeyEvents:] + 207
40 AppKit 0x00007fff8ab3586a -[NSTextView keyDown:] + 695
41 AppKit 0x00007fff8b0250fb -[NSWindow _reallySendEvent:isDelayedEvent:] + 5452
42 AppKit 0x00007fff8a9b6c86 -[NSWindow sendEvent:] + 470
43 AppKit 0x00007fff8a9b38b1 -[NSApplication sendEvent:] + 4199
44 AppKit 0x00007fff8a8dcb68 -[NSApplication run] + 711
45 AppKit 0x00007fff8a859244 NSApplicationMain + 1832
46 addobserver_test 0x00000001000066cd main + 109
47 libdyld.dylib 0x00007fff91e0b5c9 start + 1
48 ??? 0x0000000000000003 0x0 + 3
)
The first question is, do I need the #objc in front of my selector? I do not believe this should be necessary as a NSViewController is a subclass of a NSObject and that appears to make #objc unnecessary. Is this correct?
What do I need to do to make this work?
I have a sample test project at:
https://github.com/ericgorr/addobserver_test
Thank you.
In your applicationDidFinishLaunching, you are not keeping a reference to the view controller, so the object is released immediately. Then a notification is being sent to another object which took its place in memory (a __NSCFString in this case).
You need to store a strong reference to your view controller, e.g. as an instance variable.

SIGSEGV Crash with NSKeyValuePushPendingNotificationPerThread

I have an app on the Mac App Store, and I get these crash reports from my users which I cannot reproduce or figure out how to debug. It seem like something crashes due to NSManagedObjectContext reset, but it's not obvious, and users don't have a reproducible case. The main thread can have a different stack trace, but the non-main thread always has the same stack trace.
Exception Type: SIGSEGV
Exception Codes: SEGV_MAPERR at 0x41bfc026bec0
Crashed Thread: 8
Application Specific Information:
Selector name found in current argument registers: retain
Thread 0:
0 libFontParser.dylib 0x00007fff8efa7921 _ZNK20TTrueTypeFontHandler11RenderGlyphEtR27TTrueTypeQuadOutlineContextj + 89
1 libFontParser.dylib 0x00007fff8efa789e _ZNK20TTrueTypeFontHandler14GetOutlinePathEtRK18TGlyphOutlineBatch + 60
2 libFontParser.dylib 0x00007fff8efa744a FPFontCopyGlyphPath + 394
3 CoreGraphics 0x00007fff8767e913 CGFontCreateGlyphPath + 44
4 CoreGraphics 0x00007fff8767e85d CGFontCreateGlyphBitmap + 437
5 CoreGraphics 0x00007fff8767e607 _ZN14CGGlyphBuilder22create_missing_bitmapsEPK17CGGlyphIdentifiermPPK13CGGlyphBitmap + 109
6 libRIP.A.dylib 0x00007fff8b7bec2d render_glyphs + 204
7 libRIP.A.dylib 0x00007fff8b7bdf6f draw_glyph_bitmaps + 1585
8 libRIP.A.dylib 0x00007fff8b7bd8cd ripc_DrawGlyphs + 2785
9 CoreGraphics 0x00007fff87738077 draw_glyphs + 1034
10 CoreText 0x00007fff8ac50426 _ZL25DrawSbixGlyphsAtPositionsPK5TFontP6CGFontRK6TCFRefIPK8__CFDataEPKtPK7CGPointmP9CGContext17CGAffineTransformSI_ + 2990
11 CoreText 0x00007fff8abfdb73 CTFontDrawGlyphsWithAdvances + 789
12 UIFoundation 0x00007fff966f212e -[NSLineFragmentRenderingContext drawAtPoint:inContext:] + 5398
13 UIFoundation 0x00007fff96616728 __NSStringDrawingEngine + 16941
14 UIFoundation 0x00007fff966108ff _NSStringDrawingCore + 150
15 AppKit 0x00007fff93ce6d50 _NSDrawTextCell + 6954
16 AppKit 0x00007fff9421cdf8 __47-[NSTextFieldCell drawLayer:inGraphicsContext:]_block_invoke + 576
17 AppKit 0x00007fff944aa538 +[NSAppearance _performWithCurrentAppearance:usingBlock:] + 79
18 AppKit 0x00007fff93cf6739 -[NSTextFieldCell drawLayer:inGraphicsContext:] + 225
19 AppKit 0x00007fff93cf6470 +[NSGraphicsContext configureGraphicsContextForCALayer:withCGContext:andRenderWithHandler:] + 97
20 QuartzCore 0x00007fff939f1e93 CABackingStoreUpdate_ + 3306
21 QuartzCore 0x00007fff939f11a3 ___ZN2CA5Layer8display_Ev_block_invoke + 59
22 QuartzCore 0x00007fff939f115f x_blame_allocations + 81
23 QuartzCore 0x00007fff939f0c5c _ZN2CA5Layer8display_Ev + 1546
24 AppKit 0x00007fff93ce039f _NSBackingLayerDisplay + 617
25 QuartzCore 0x00007fff939f0381 _ZN2CA5Layer17display_if_neededEPNS_11TransactionE + 603
26 QuartzCore 0x00007fff939efabd _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 35
27 QuartzCore 0x00007fff939ef24e _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242
28 QuartzCore 0x00007fff939eeea4 _ZN2CA11Transaction6commitEv + 390
29 QuartzCore 0x00007fff939ffcad _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 71
30 CoreFoundation 0x00007fff8bbd0da7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
31 CoreFoundation 0x00007fff8bbd0d00 __CFRunLoopDoObservers + 368
32 CoreFoundation 0x00007fff8bbc2878 CFRunLoopRunSpecific + 328
33 HIToolbox 0x00007fff918f1aef RunCurrentEventLoopInMode + 235
34 HIToolbox 0x00007fff918f176e ReceiveNextEventCommon + 179
35 HIToolbox 0x00007fff918f16ab _BlockUntilNextEventMatchingListInModeWithFilter + 71
36 AppKit 0x00007fff93bb0f81 _DPSNextEvent + 964
37 AppKit 0x00007fff93bb0730 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 194
38 AppKit 0x00007fff93ba4593 -[NSApplication run] + 594
39 AppKit 0x00007fff93b8fa14 NSApplicationMain + 1832
40 libdyld.dylib 0x00007fff88d605c9 start + 1
...
Thread 7:
0 libsystem_kernel.dylib 0x00007fff94d1b94a __workq_kernreturn + 10
1 libsystem_pthread.dylib 0x00007fff9508740d start_wqthread + 13
Thread 8 Crashed:
0 libobjc.A.dylib 0x00007fff90c740dd objc_msgSend + 29
1 Foundation 0x00007fff92461d24 NSKeyValuePushPendingNotificationPerThread + 446
2 Foundation 0x00007fff9240968f NSKeyValueWillChange + 465
3 Foundation 0x00007fff924bc33e -[NSObject(NSKeyValueObservingPrivate) _willChangeValuesForKeys:] + 234
4 CoreData 0x00007fff8d9fdd6d -[NSFaultHandler turnObject:intoFaultWithContext:] + 221
5 CoreData 0x00007fff8da28641 -[NSManagedObjectContext(_NSInternalAdditions) _disposeObjects:count:notifyParent:] + 353
6 CoreData 0x00007fff8da27c78 -[NSManagedObjectContext(_NSInternalAdditions) _dispose:] + 392
7 CoreData 0x00007fff8da27821 -[NSManagedObjectContext _dealloc__] + 337
8 CoreData 0x00007fff8da563ab __internalBlockToDeallocNSManagedObjectContext_block_invoke + 75
9 CoreData 0x00007fff8da1c246 developerSubmittedBlockToNSManagedObjectContextPerform + 182
10 libdispatch.dylib 0x00007fff8f122c13 _dispatch_client_callout + 8
11 libdispatch.dylib 0x00007fff8f126365 _dispatch_queue_drain + 1100
12 libdispatch.dylib 0x00007fff8f127ecc _dispatch_queue_invoke + 202
13 libdispatch.dylib 0x00007fff8f1256b7 _dispatch_root_queue_drain + 463
14 libdispatch.dylib 0x00007fff8f133fe4 _dispatch_worker_thread3 + 91
15 libsystem_pthread.dylib 0x00007fff95089637 _pthread_wqthread + 729
16 libsystem_pthread.dylib 0x00007fff9508740d start_wqthread + 13
Any idea how to find out what's causing the issue and possibly fix it? I've tried enabling zombies, setting NSBindingDebugLogLevel to 1, and running Zombies instrument, but no luck.

Strange crash when bringing up a window on Sandboxed cocoa app only on OSX 10.8.3

This one is quite weird. I recently upgraded to Mountain Lion on my dev machine and now every time I bring up the main project window of my app it crashes. The strange thing is that it only happens on 10.8.3 and it only happen if I sandbox the app. I have another test machine running 10.8.2 (also Mountain Lion) and the crash does not happen. Also, if I recreate the app without sandboxing it does not crash. This app is actually created with an implementation of common lisp the uses a cocoa bridge called CCL.
Here are some of the reports I get in the console when my app crashes:
4/19/13 11:30:15.605 AM AgentCubes[56676]: kCGErrorIllegalArgument: _getWindowRegion: Invalid window
4/19/13 11:30:15.606 AM AgentCubes[56676]: CGSSetWindowLevel: Invalid window 0x137c
4/19/13 11:30:15.607 AM AgentCubes[56676]: PSsetwindowlevel, error setting window level (1000)
4/19/13 11:30:15.607 AM AgentCubes[56676]: CGSClearWindowTags: Invalid window 0x137c
4/19/13 11:30:15.607 AM AgentCubes[56676]: CGSSetIgnoresCycle: error 1000 setting or clearing window tags
4/19/13 11:30:15.623 AM AgentCubes[56676]: *** Assertion failure in -[NativeScrollView scrollerImpPair:updateScrollerStyleForNewRecommendedScrollerStyle:], /SourceCache/AppKit/AppKit-1187.37/AppKit.subproj/NSScrollView.m:5402
4/19/13 11:30:15.623 AM AgentCubes[56676]: An uncaught exception was raised
4/19/13 11:30:15.624 AM AgentCubes[56676]: Invalid parameter not satisfying: scrollerImpPair == SCROLLER_IMP_PAIR
and the big trace:
4/19/13 11:30:15.626 AM AgentCubes[56676]: (
0 CoreFoundation 0x99cbee9b __raiseError + 219
1 libobjc.A.dylib 0x90a6552e objc_exception_throw + 230
2 CoreFoundation 0x99c1e6a8 +[NSException raise:format:arguments:] + 136
3 Foundation 0x93dfb814 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
4 AppKit 0x977cd7ab -[NSScrollView(NSPrivate) scrollerImpPair:updateScrollerStyleForNewRecommendedScrollerStyle:] + 150
5 AppKit 0x977cd6a5 +[NSScrollerImpPair _updateAllScrollerImpPairsForNewRecommendedScrollerStyle:] + 406
6 AppKit 0x977cd4ff +[NSScrollerImpPair _scrollerStyleRecommendationChanged:] + 159
7 Foundation 0x93e52152 __57-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke_0 + 49
8 CoreFoundation 0x99c80861 ___CFXNotificationPost_block_invoke_0 + 257
9 CoreFoundation 0x99bcbe9a _CFXNotificationPost + 2794
10 Foundation 0x93e3ac88 -[NSNotificationCenter postNotificationName:object:userInfo:] + 92
11 AppKit 0x977cd3f5 -[_NSScrollerStyleRecommender setRecommendedScrollerStyleAndNotify:] + 248
12 AppKit 0x977cd2e3 __75-[_NSScrollerStyleRecommender scrollerStyleRecommendationUpdateTimerFired:]_block_invoke_0 + 43
13 AppKit 0x97eff42f __block_global_0 + 32
14 libdispatch.dylib 0x98f10f8f _dispatch_call_block_and_release + 15
15 libdispatch.dylib 0x98f0cc82 _dispatch_client_callout + 46
16 libdispatch.dylib 0x98f122e3 _dispatch_main_queue_callback_4CF + 223
17 CoreFoundation 0x99bbac39 __CFRunLoopRun + 1961
18 CoreFoundation 0x99bba02a CFRunLoopRunSpecific + 378
19 CoreFoundation 0x99bb9e9b CFRunLoopRunInMode + 123
20 HIToolbox 0x91e16f5a RunCurrentEventLoopInMode + 242
21 HIToolbox 0x91e16cc9 ReceiveNextEventCommon + 374
22 HIToolbox 0x91e16b44 BlockUntilNextEventMatchingListInMode + 88
23 AppKit 0x976e99aa _DPSNextEvent + 724
24 AppKit 0x976e91dc -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 119
25 AppKit 0x976df63c -[NSApplication run] + 855
26 AgentCubes 0x0001991d ffcall_return + 0
27 ??? 0x003cbf9c 0x0 + 3981212
28 ??? 0x003cbf9c 0x0 + 3981212
29 AgentCubes 0x00019f79 func_start + 94
30 AgentCubes 0x0001c52e main + 1310
31 AgentCubes 0x00033fb4 _start + 207
32 AgentCubes 0x00033ee4 start + 40
)
and finally:
4/19/13 11:30:15.627 AM AgentCubes[56676]: *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: scrollerImpPair == SCROLLER_IMP_PAIR'
*** Call stack at first throw:
(
0 CoreFoundation 0x99cbee9b __raiseError + 219
1 libobjc.A.dylib 0x90a6552e objc_exception_throw + 230
2 CoreFoundation 0x99c1e6a8 +[NSException raise:format:arguments:] + 136
3 Foundation 0x93dfb814 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
4 AppKit 0x977cd7ab -[NSScrollView(NSPrivate) scrollerImpPair:updateScrollerStyleForNewRecommendedScrollerStyle:] + 150
5 AppKit 0x977cd6a5 +[NSScrollerImpPair _updateAllScrollerImpPairsForNewRecommendedScrollerStyle:] + 406
6 AppKit 0x977cd4ff +[NSScrollerImpPair _scrollerStyleRecommendationChanged:] + 159
7 Foundation 0x93e52152 __57-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke_0 + 49
8 CoreFoundation 0x99c80861 ___CFXNotificationPost_block_invoke_0 + 257
9 CoreFoundation 0x99bcbe9a _CFXNotificationPost + 2794
10 Foundation 0x93e3ac88 -[NSNotificationCenter postNotificationName:object:userInfo:] + 92
11 AppKit 0x977cd3f5 -[_NSScrollerStyleRecommender setRecommendedScrollerStyleAndNotify:] + 248
12 AppKit 0x977cd2e3 __75-[_NSScrollerStyleRecommender scrollerStyleRecommendationUpdateTimerFired:]_block_invoke_0 + 43
13 AppKit 0x97eff42f __block_global_0 + 32
14 libdispatch.dylib 0x98f10f8f _dispatch_call_block_and_release + 15
15 libdispatch.dylib 0x98f0cc82 _dispatch_client_callout + 46
16 libdispatch.dylib 0x98f122e3 _dispatch_main_queue_callback_4CF + 223
17 CoreFoundation 0x99bbac39 __CFRunLoopRun + 1961
18 CoreFoundation 0x99bba02a CFRunLoopRunSpecific + 378
19 CoreFoundation 0x99bb9e9b CFRunLoopRunInMode + 123
20 HIToolbox 0x91e16f5a RunCurrentEventLoopInMode + 242
21 HIToolbox 0x91e16cc9 ReceiveNextEventCommon + 374
22 HIToolbox 0x91e16b44 BlockUntilNextEventMatchingListInMode + 88
23 AppKit 0x976e99aa _DPSNextEvent + 724
24 AppKit 0x976e91dc -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 119
25 AppKit 0x976df63c -[NSApplication run] + 855
26 AgentCubes 0x0001991d ffcall_return + 0
27 ??? 0x003cbf9c 0x0 + 3981212
28 ??? 0x003cbf9c 0x0 + 3981212
29 AgentCubes 0x00019f79 func_start + 94
30 AgentCubes 0x0001c52e main + 1310
31 AgentCubes 0x00033fb4 _start + 207
32 AgentCubes 0x00033ee4 start + 40
)
I am very confused by all this and I am wondering what could have changed in 10.8.3 that interacts badly with the sandboxing?

Resources