In my macOS application I have a very rare crash which I cannot reproduce and I can't find out what causes it.
Please see the call stack below.
Here are my thoughts:
It seems to happen on application start because there's NSPersistentUIRestorer in the call stack.
Then main window view (NSThemeFrame) changes its frame size and sends NSViewGeometryInWindowDidChangeNotification to the children.
Some button tries to setup mouse tracking with _setMouseTrackingForCell and crashes becase some subview (or superview?) is deallocated.
Right now I'm out of ideas and I would appreciate any advice or suggestion. Thank you in advance.
Call stack:
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x00006080044e6820
Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x7fff50eb4ea9 objc_msgSend + 41
1 AppKit 0x7fff272c62d5 -[NSView(NSInternal) _uninstallTrackingArea:] + 326
2 AppKit 0x7fff2726525e -[NSView removeTrackingArea:] + 312
3 AppKit 0x7fff2729d3c7 -[NSCell(NSPrivate_CellMouseTracking) _setMouseTrackingInRect:ofView:withConfiguration:] + 101
4 AppKit 0x7fff2729d2fe -[NSCell(NSPrivate_CellMouseTracking) _setMouseTrackingInRect:ofView:] + 90
5 AppKit 0x7fff2729d1bb -[NSButtonCell _setMouseTrackingInRect:ofView:] + 84
6 AppKit 0x7fff2729d15c -[NSControl _setMouseTrackingForCell:] + 102
7 AppKit 0x7fff2729d0af -[NSButton(NSButtonBorder) _setMouseTrackingForCell:] + 47
8 CoreFoundation 0x7fff29ca5edc __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
9 CoreFoundation 0x7fff29ca5daa _CFXRegistrationPost + 458
10 CoreFoundation 0x7fff29ca5ae1 ___CFXNotificationPost_block_invoke + 225
11 CoreFoundation 0x7fff29c63880 -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1664
12 CoreFoundation 0x7fff29c629b7 _CFXNotificationPost + 599
13 Foundation 0x7fff2bd728c7 -[NSNotificationCenter postNotificationName:object:userInfo:] + 66
14 AppKit 0x7fff27ad9859 NSViewHierarchyNoteGeometryInWindowDidChange + 160
15 AppKit 0x7fff27ad9a3a NSViewHierarchyNoteGeometryInWindowDidChange + 641
16 AppKit 0x7fff27ad9a3a NSViewHierarchyNoteGeometryInWindowDidChange + 641
17 AppKit 0x7fff27ad9a3a NSViewHierarchyNoteGeometryInWindowDidChange + 641
18 AppKit 0x7fff27ad9a3a NSViewHierarchyNoteGeometryInWindowDidChange + 641
19 AppKit 0x7fff27ad9a3a NSViewHierarchyNoteGeometryInWindowDidChange + 641
20 AppKit 0x7fff2720e9a7 -[NSView _invalidateFocus] + 63
21 AppKit 0x7fff2724e7dc -[NSView setFrameSize:] + 1902
22 AppKit 0x7fff27264b1e -[NSView setFrame:] + 371
23 AppKit 0x7fff2726f49c -[NSThemeFrame _relayoutAuxiliaryViewsOfType:] + 163
24 AppKit 0x7fff2726f3e6 -[NSThemeFrame relayoutAuxiliaryViewsOfType:] + 27
25 AppKit 0x7fff2726ec33 -[NSTitlebarViewController insertChildViewController:atIndex:] + 386
26 AppKit 0x7fff27a88caa -[NSWindowStackController _makeTabBarForWindow:visible:] + 221
27 AppKit 0x7fff27a8bc77 -[NSWindowStackController _addSyncedTabBarItemForWindow:atIndex:] + 625
28 AppKit 0x7fff27a89b96 -[NSWindowStackController insertWindow:atIndex:] + 628
29 AppKit 0x7fff27a8990b -[NSWindowStackController addWindow:] + 437
30 AppKit 0x7fff276180ff -[NSWindow(NSWindowTabbing) _restoreTabbedWindowStateWithCoder:] + 299
31 AppKit 0x7fff27533c82 -[NSWindow restoreStateWithCoder:] + 96
32 AppKit 0x7fff274fcf17 restorePersistentStateWithWindowRestoration + 1004
33 AppKit 0x7fff27533be2 -[NSPersistentUIRestorer invokeRestoration:] + 572
34 AppKit 0x7fff27533947 __79-[NSPersistentUIRestorer finishedRestoringWindowsWithZOrder:completionHandler:]_block_invoke + 194
35 AppKit 0x7fff27533723 +[NSWindow _batchMinimizeWindowsWithBlock:] + 86
36 AppKit 0x7fff274fd475 -[NSPersistentUIRestorer finishedRestoringWindowsWithZOrder:completionHandler:] + 705
37 AppKit 0x7fff27532a79 __82-[NSPersistentUIRestorer restoreStateFromRecords:usingDelegate:completionHandler:]_block_invoke_3 + 168
38 AppKit 0x7fff2753298e __99-[NSApplication(NSPersistentUIRestorationSupport) _restoreWindowWithRestoration:completionHandler:]_block_invoke + 365
39 AppKit 0x7fff27cb94e3 -[NSDocument(NSPersistentUISupport) restoreDocumentWindowWithIdentifier:state:completionHandler:] + 497
40 AppKit 0x7fff2777d3c4 -[NSDocumentControllerPersistentRestoration loadedDocument:forAutoID:] + 176
41 AppKit 0x7fff27782221 __89-[NSDocumentController reopenDocumentForURL:withContentsOfURL:display:completionHandler:]_block_invoke_2 + 185
42 AppKit 0x7fff27790f70 ___NSMainRunLoopPerformBlock_block_invoke + 25
43 CoreFoundation 0x7fff29cae87c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
44 CoreFoundation 0x7fff29c91253 __CFRunLoopDoBlocks + 275
45 CoreFoundation 0x7fff29c91018 __CFRunLoopRun + 3128
46 CoreFoundation 0x7fff29c90153 CFRunLoopRunSpecific + 483
47 HIToolbox 0x7fff28f7ad96 RunCurrentEventLoopInMode + 286
48 HIToolbox 0x7fff28f7ab06 ReceiveNextEventCommon + 613
49 HIToolbox 0x7fff28f7a884 _BlockUntilNextEventMatchingListInModeWithFilter + 64
50 AppKit 0x7fff2722ba73 _DPSNextEvent + 2085
51 AppKit 0x7fff279c1e34 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 3044
52 AppKit 0x7fff27220885 -[NSApplication run] + 764
53 AppKit 0x7fff271efa72 NSApplicationMain + 804
54 MyApp 0x106be1479 main (AppDelegate.swift:17)
55 libdyld.dylib 0x7fff51adc015 start + 1
Update 1:
Running application with zombies shows the following warnings in the output
objc[67272]: Class _NSZombie_CFReadStream is implemented in both ?? (0x6040000bb290) and ?? (0x6040000b8150). One of the two will be used. Which one is undefined.
objc[67272]: Class _NSZombie_NSMachPort is implemented in both ?? (0x604000151990) and ?? (0x6040001532d0). One of the two will be used. Which one is undefined.
objc[67272]: Class _NSZombie_CFMachPort is implemented in both ?? (0x604000157110) and ?? (0x60400015c0d0). One of the two will be used. Which one is undefined.
objc[67272]: Class _NSZombie_NSConcreteTask is implemented in both ?? (0x604000157250) and ?? (0x604000153a50). One of the two will be used. Which one is undefined.
objc[67272]: Class _NSZombie_NSConcreteFileHandle is implemented in both ?? (0x60400016f450) and ?? (0x604000170c90). One of the two will be used. Which one is undefined.
objc[67272]: Class _NSZombie_NSConcreteFileHandle is implemented in both ?? (0x60400016f450) and ?? (0x6040001724d0). One of the two will be used. Which one is undefined.
Update 2:
I managed to reproduce the exact call stack using symbolic break points (but still have never seen the actual crash).
Then using LLDB I requested the information about the button and found out that it is just a regular button with recessed style. Not sure why it causes crash sometimes. May be it's just the first leaf in view hierarchy tree.
For curious ones, here's how I got that information:
(lldb) expr -l Swift -- import Cocoa
(lldb) po $arg1
<NSButton: 0x60f0000ebdb0>
(lldb) expr -l Swift -- let $btn = unsafeBitCast(0x60f0000f7660, to: NSButton.self)
(lldb) expr -l Swift -- print($btn.title)
Related
I have a function:
NSTimer *learnUSBTimer=nil;
- (void)showUSBWindow:(id)sender {
[self updateDeviceButton:#"Cancel"];
[self hideDeviceClearButton:TRUE];
[selectedDeviceField setStringValue:#"Insert the USB device..."];
learnUSBMode=1;
if(learnUSBTimer)
{
if([learnUSBTimer isValid])[learnUSBTimer invalidate];
learnUSBTimer=nil;
}
}
And it seems my message sent to the timer object is being sent to the UI object:
2018-02-19 14:02:34.649581-0500 TokenLock[4068:819373] -[NSBox isValid]: unrecognized selector sent to instance 0x60000016bc40
2018-02-19 14:02:34.649691-0500 TokenLock[4068:819373] [General] -[NSBox isValid]: unrecognized selector sent to instance 0x60000016bc40
2018-02-19 14:02:34.651799-0500 TokenLock[4068:819373] [General] (
0 CoreFoundation 0x00007fff4f33833b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x00007fff7607c942 objc_exception_throw + 48
2 CoreFoundation 0x00007fff4f3cf5e4 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x00007fff4f2aff03 ___forwarding___ + 1443
4 CoreFoundation 0x00007fff4f2af8d8 _CF_forwarding_prep_0 + 120
5 TokenLock 0x0000000100014cdc -[AppController showUSBWindow:] + 252
6 AppKit 0x00007fff4d02375a -[NSApplication(NSResponder) sendAction:to:from:] + 312
7 AppKit 0x00007fff4cac9933 -[NSControl sendAction:to:] + 86
8 AppKit 0x00007fff4cac985b __26-[NSCell _sendActionFrom:]_block_invoke + 136
9 AppKit 0x00007fff4cac9761 -[NSCell _sendActionFrom:] + 183
10 AppKit 0x00007fff4cb0aa18 -[NSButtonCell _sendActionFrom:] + 97
11 AppKit 0x00007fff4cac7fca -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2438
12 AppKit 0x00007fff4cb0a75f -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 777
13 AppKit 0x00007fff4cac6a64 -[NSControl mouseDown:] + 965
14 AppKit 0x00007fff4d1c2959 -[NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:] + 5891
15 AppKit 0x00007fff4d1bf5b0 -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 2359
16 AppKit 0x00007fff4d1be85c -[NSWindow(NSEventRouting) sendEvent:] + 497
17 AppKit 0x00007fff4d01f617 -[NSApplication(NSEvent) sendEvent:] + 307
18 AppKit 0x00007fff4c880d9d -[NSApplication run] + 812
19 AppKit 0x00007fff4c84ff1a NSApplicationMain + 804
20 TokenLock 0x0000000100001ea1 main + 97
21 TokenLock 0x0000000100001e34 start + 52
)
I dont understand how my NSTimer is being somehow assigned to the UI Box being clicked to execute the function?
It seems that there will be some memory management issue in your code. And the objects are not properly allocated/ deallocated or not initialised deinitialised properly.
So to solve this issue just run your code by enabling zombies into your project target settings.
It turns out this timer fires once. I was not setting it to nil in that code and so it became essentially an orphan because the system released the actual timer object after.
Setting it to nil on firing fixes the issue.
My macOS app uses a NSTableView with 'Floats Group Row' enabled. This works without problems on my test Macs. However, on a regular basis I receive crash reports from users with:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'self.floatingGroupRowView should be equal to the given row view!'
Does anyone know the conditions for this error?
The last part of the crashlog look similar to this:
0 CoreFoundation 0x00007fff51db6ff3 __exceptionPreprocess + 147
1 libobjc.A.dylib 0x00007fff78992c76 objc_exception_throw + 48
2 CoreFoundation 0x00007fff51dbcda2 +[NSException raise:format:arguments:] + 98
3 Foundation 0x00007fff53ebb260 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 192
4 AppKit 0x00007fff4f656e9f -[NSTableRowData _updateFloatingGroupRowView:row:] + 421
5 AppKit 0x00007fff4f4245db -[NSTableRowData _updateFrameRowView:row:] + 100
6 AppKit 0x00007fff4fd03fca __48-[NSTableRowData _doAutomaticRowHeightsForRows:]_block_invoke.1004 + 47
7 AppKit 0x00007fff4f40eae2 -[NSTableRowData enumerateAvailableRowViewsUsingBlock:] + 139
8 AppKit 0x00007fff4fd03ede -[NSTableRowData _doAutomaticRowHeightsForRows:] + 274
9 AppKit 0x00007fff4fd07157 __59-[NSTableRowData _automaticRowHeightsUpdateVisibleRowViews]_block_invoke.1494 + 141
10 AppKit 0x00007fff4fd06d05 -[NSTableRowData _keepTopRowStable:andDoWorkUntilDone:] + 535
11 AppKit 0x00007fff4fd07075 -[NSTableRowData _automaticRowHeightsUpdateVisibleRowViews] + 161
12 AppKit 0x00007fff4f415d85 -[NSTableRowData updateVisibleRowViews] + 261
13 AppKit 0x00007fff4f5bf24e -[NSTableRowData prepareContentInRect:] + 106
14 AppKit 0x00007fff4f5bed46 -[NSTableView prepareContentInRect:] + 303
15 AppKit 0x00007fff4fbbf7b1 __38-[NSView _pullInExtraTilesForOverdraw]_block_invoke + 562
16 AppKit 0x00007fff4f484a19 -[NSView _performWorkOnTilesFromRect:renderedContentRect:maximumRect:scrollVelocity:handler:] + 1544
17 AppKit 0x00007fff4f4841f2 -[NSView _pullInExtraTilesForOverdraw] + 854
18 AppKit 0x00007fff4f483e6d -[NSView _doIdlePrefetch] + 37
Unfortunately, these crashlogs don't point consistently to one particular line in my code.
I am having inconsistent behavior in my app, where sometimes a draw call isn't received by MyView, even after following the same steps where it is received.
The thing is, in the backtrace for drawRect, there are no frames that tell me what is happening within our code that causes the message to be sent
Here is an example backtrace (top 2 frames don't matter):
2 MyApp 0x00000001000112a5 -[MyView drawRect:] + 1429
3 AppKit 0x00007fff8bfc87be -[NSView(NSInternal) _recursive:displayRectIgnoringOpacity:inGraphicsContext:CGContext:topView:shouldChangeFontReferenceColor:] + 1331
4 AppKit 0x00007fff8bfc8156 __46-[NSView(NSLayerKitGlue) drawLayer:inContext:]_block_invoke + 242
5 AppKit 0x00007fff8bfc7caf -[NSView(NSLayerKitGlue) _drawViewBackingLayer:inContext:drawingHandler:] + 2403
6 AppKit 0x00007fff8bfc7341 -[NSView(NSLayerKitGlue) drawLayer:inContext:] + 108
7 QuartzCore 0x00007fff88045b19 CABackingStoreUpdate_ + 3494
8 QuartzCore 0x00007fff88044d6d ___ZN2CA5Layer8display_Ev_block_invoke + 59
9 QuartzCore 0x00007fff88044759 _ZN2CA5Layer8display_Ev + 1565
10 AppKit 0x00007fff8bfc6318 _NSBackingLayerDisplay + 641
11 AppKit 0x00007fff8bfb8878 -[_NSViewBackingLayer display] + 818
12 QuartzCore 0x00007fff880364a5 _ZN2CA5Layer17display_if_neededEPNS_11TransactionE + 603
13 QuartzCore 0x00007fff88035fcd _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 35
14 QuartzCore 0x00007fff880354a1 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
15 QuartzCore 0x00007fff880350ec _ZN2CA11Transaction6commitEv + 508
16 QuartzCore 0x00007fff88040977 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 71
17 CoreFoundation 0x00007fff88f3efc7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
18 CoreFoundation 0x00007fff88f3ef37 __CFRunLoopDoObservers + 391
19 CoreFoundation 0x00007fff88f1de58 CFRunLoopRunSpecific + 328
20 HIToolbox 0x00007fff93726935 RunCurrentEventLoopInMode + 235
21 HIToolbox 0x00007fff9372676f ReceiveNextEventCommon + 432
22 HIToolbox 0x00007fff937265af _BlockUntilNextEventMatchingListInModeWithFilter + 71
23 AppKit 0x00007fff8be5fdf6 _DPSNextEvent + 1067
24 AppKit 0x00007fff8be5f226 -[NSApplication _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 454
25 AppKit 0x00007fff8be53d80 -[NSApplication run] + 682
26 AppKit 0x00007fff8be1d368 NSApplicationMain + 1176
27 MyApp 0x000000010000d102 main + 34
28 libdyld.dylib 0x00007fff8ec5c5ad start + 1
I just want to figure out if it's possible to see exactly what message/event that's happening that results in the -drawRect, so I can see why -drawRect is occasionally not being received
Note that I have seen this thread:How to tell what's causing drawRect to be called?, but it doesn't answer the question I have
Okay, so I know I said the top 2 frames didn't matter, but turns out they did.
Just a brain fart, I had set the breakpoint 3 stack frames deep, and if I had just set it in drawRect, I would see that it is in fact being called every time I expect it to. There was an if statement in the 2nd stack frame that prevented execution into the top stack frame that I was breaking on when writing this question T.T
i want to know if any of you have faced an issue that you have a window and you click a few buttons and everything work fine, but then you get this
2014-07-29 23:08:23.448 Touring[2807:707] -[__NSCFString btnVenue:]: unrecognized selector sent to instance 0x7d0f14b0
2014-07-29 23:08:23.466 Touring[2807:707] (
0 CoreFoundation 0x9a666471 __raiseError + 193
1 libobjc.A.dylib 0x976be091 objc_exception_throw + 162
2 CoreFoundation 0x9a66acb3 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x9a5b6522 ___forwarding___ + 1010
4 CoreFoundation 0x9a5b610e _CF_forwarding_prep_0 + 14
5 libobjc.A.dylib 0x976ca2af -[NSObject performSelector:withObject:] + 70
6 AppKit 0x90d188a5 -[NSApplication sendAction:to:from:] + 438
7 AppKit 0x90d186ad -[NSControl sendAction:to:] + 102
8 AppKit 0x90d67c7b -[NSCell _sendActionFrom:] + 159
9 AppKit 0x90d82f2a -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2465
10 AppKit 0x90d82161 -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 513
11 AppKit 0x90d81785 -[NSControl mouseDown:] + 690
12 AppKit 0x90cfda9d -[NSWindow sendEvent:] + 11953
13 AppKit 0x90c9991d -[NSApplication sendEvent:] + 4034
14 AppKit 0x90ade1bc -[NSApplication run] + 823
15 AppKit 0x90ac6ff8 NSApplicationMain + 1165
16 ??? 0x030e6948 0x0 + 51276104
17 ??? 0x030e6768 0x0 + 51275624
18 ??? 0x00a0e0bc 0x0 + 10543292
19 ??? 0x00a0e207 0x0 + 10543623
20 Touring 0x001b5bfc mono_jit_runtime_invoke + 828
21 Touring 0x00262ebe mono_runtime_invoke + 126
22 Touring 0x00267328 mono_runtime_exec_main + 376
23 Touring 0x00267675 mono_runtime_run_main + 725
24 Touring 0x00114d75 mono_jit_exec + 149
25 Touring 0x000c57e8 main + 1720
26 libdyld.dylib 0x94793701 start + 1
Any kind of help will be very appreciated.
Ok again, after trying a few things without luck, came to my mind to go to the project properties and go to the Mac Build and check the "Use the SGen generational garbage collector" (i don't know if on one of my test i un check this or came like that) but after this, many issues of crashing we're apparentely solved.
Have to try more deep to see if it work 100%.
Any way, thanks to anyone who may read this.
I have a subclass of NSDocument that crashes whenever I use [self close] to avoid the default 'save' dialog for new documents:
2013-02-25 15:23:06.338 MyApp[692:403] An uncaught exception was raised
2013-02-25 15:23:06.338 MyApp[692:403] NSWindow: -_newFirstResponderAfterResigining is not a valid message outside of a responder's implementation of -resignFirstResponder.
2013-02-25 15:23:06.356 MyApp[692:403] (
0 CoreFoundation 0x00007fff8b2cdf56 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff88c00d5e objc_exception_throw + 43
2 CoreFoundation 0x00007fff8b2cdd8a +[NSException raise:format:arguments:] + 106
3 CoreFoundation 0x00007fff8b2cdd14 +[NSException raise:format:] + 116
4 AppKit 0x00007fff858e0c34 -[NSWindow _newFirstResponderAfterResigning] + 164
5 AppKit 0x00007fff85882c8a -[NSTextView(NSSharing) resignFirstResponder] + 54
6 AppKit 0x00007fff8536dd79 -[NSWindow makeFirstResponder:] + 429
7 AppKit 0x00007fff85488dfb -[NSWindow dealloc] + 802
8 AppKit 0x00007fff8528b955 -[NSWindow release] + 535
9 AppKit 0x00007fff858b541c __destroy_helper_block_4 + 26
10 libsystem_blocks.dylib 0x00007fff8702b174 _Block_release + 181
11 libdispatch.dylib 0x00007fff84ab28f2 _dispatch_main_queue_callback_4CF + 308
12 CoreFoundation 0x00007fff8b262e7c __CFRunLoopRun + 1724
13 CoreFoundation 0x00007fff8b262486 CFRunLoopRunSpecific + 230
14 HIToolbox 0x00007fff8d64e2bf RunCurrentEventLoopInMode + 277
15 HIToolbox 0x00007fff8d65556d ReceiveNextEventCommon + 355
16 HIToolbox 0x00007fff8d6553fa BlockUntilNextEventMatchingListInMode + 62
17 AppKit 0x00007fff85252779 _DPSNextEvent + 659
18 AppKit 0x00007fff8525207d -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 135
19 AppKit 0x00007fff8524e9b9 -[NSApplication run] + 470
20 AppKit 0x00007fff854caeac NSApplicationMain + 867
21 MyApp 0x00000001059098d2 main + 34
22 MyApp 0x00000001059098a4 start + 52
23 ??? 0x0000000000000003 0x0 + 3
)
Has anyone seen this before or can anyone suggest a better/proper way to close an NSDocument without the save dialog being shown?
So judging by your followup comments, what you're trying to do is suppress the standard close confirmation sheet under specific circumstances. Some ways to do that:
Adopt autosaving-in-place, which moves away from the ancient paradigm of manually saving documents
Override -[NSDocument canCloseDocumentWithDelegate:shouldCloseSelector:contextInfo:] so it tells the delegate "yes, you can close", rather than presenting a sheet
Once a post is made, call [document updateChangeCount: NSChangeCleared] to inform the document that you consider it to be saved