Random crash on monomac/Xamarin.Mac - cocoa

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.

Related

How can I debug a crash from the call to the undo command on a NSMenuItem?

I would like to be able to fix this crash on my OSX application, I've been seeing the crashes on my firebase console when users perform an undo action, from what I can see probably from a key command. But I have no idea why & where in the app is this happening.
Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x7fff6c60981d objc_msgSend + 29
1 Foundation 0x7fff360047a7 -[_NSUndoStack popAndInvoke] + 187
2 Foundation 0x7fff36004514 -[NSUndoManager undoNestedGroup] + 296
3 AppKit 0x7fff30ff5d49 -[NSCellUndoManager undo] + 102
4 AppKit 0x7fff30d36437 -[NSApplication(NSResponder) sendAction:to:from:] + 299
5 AppKit 0x7fff30e46aee -[NSMenuItem _corePerformAction] + 312
6 AppKit 0x7fff30e4686a -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 106
7 AppKit 0x7fff30e45767 -[NSMenu performKeyEquivalent:] + 412
8 AppKit 0x7fff3127b27b routeKeyEquivalent + 521
9 AppKit 0x7fff30c974dd -[NSApplication(NSEvent) sendEvent:] + 1161
10 AppKit 0x7fff30ae421f -[NSApplication run] + 707
11 AppKit 0x7fff30ab5ff6 NSApplicationMain + 777
12 libdyld.dylib 0x7fff6d7bdcc9 start + 1
Any help is greatly appreciated.

EXC_BAD_ACCESS on application start

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)

Cocoa UI IBAction call seems to corrupt NSTimer

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.

removeobjectAtIndex: causes index to be -1;

I have a NSTableView that is populated by an array called tableArray. I have a button that is supposed to remove the selected item from the array. In my removeItem: method:
[tableArray removeObjectAtIndex:[tableView selectedRow];
[tableView reloadData];
But I get the error:
2015-05-13 18:16:45.283 FileShedb1.0[979:303] *** -[__NSArrayM objectAtIndex:]: index 18446744073709551615 beyond bounds [0 .. 0]
2015-05-13 18:16:45.288 FileShedb1.0[979:303] (
0 CoreFoundation 0x00007fff8d35ff56 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff93119d5e objc_exception_throw + 43
2 CoreFoundation 0x00007fff8d2ed392 -[__NSArrayM objectAtIndex:] + 274
3 FileShedb1.0 0x00000001000028a9 -[MPOMainWindowController tableViewSelectionDidChange:] + 201
4 Foundation 0x00007fff8cca0d0e __-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke_1 + 47
5 CoreFoundation 0x00007fff8d3087ba _CFXNotificationPost + 2634
6 Foundation 0x00007fff8cc8cfc3 -[NSNotificationCenter postNotificationName:object:userInfo:] + 65
7 AppKit 0x00007fff8ab10049 -[NSTableView _sendSelectionChangedNotificationForRows:columns:] + 203
8 AppKit 0x00007fff8aae6b0a -[NSTableView _enableSelectionPostingAndPost] + 425
9 AppKit 0x00007fff8aadcd75 -[NSTableView _tileAndRedisplayAll] + 358
10 FileShedb1.0 0x00000001000027bc -[MPOMainWindowController removeFile:] + 188
11 CoreFoundation 0x00007fff8d34f70d -[NSObject performSelector:withObject:] + 61
12 AppKit 0x00007fff8aaa98ca -[NSApplication sendAction:to:from:] + 139
13 AppKit 0x00007fff8aaa97fe -[NSControl sendAction:to:] + 88
14 AppKit 0x00007fff8aaa9729 -[NSCell _sendActionFrom:] + 137
15 AppKit 0x00007fff8aaa8bec -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2014
16 AppKit 0x00007fff8ab28b74 -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 489
17 AppKit 0x00007fff8aaa77f6 -[NSControl mouseDown:] + 786
18 AppKit 0x00007fff8aa72c98 -[NSWindow sendEvent:] + 6306
19 AppKit 0x00007fff8aa0c3a5 -[NSApplication sendEvent:] + 5593
20 AppKit 0x00007fff8a9a2a0e -[NSApplication run] + 555
21 AppKit 0x00007fff8ac1eeac NSApplicationMain + 867
22 FileShedb1.0 0x00000001000014c2 main + 34
23 FileShedb1.0 0x0000000100001494 start + 52
)
Anyone know why i'm getting the error?
If no row is selected, selectedRow row returns -1. Put a check for this.
Checkout apple's documentation.

Proper way to close NSDocument programmatically

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

Resources