I'm creating an application in RubyCocoa and I have this code:
fileContents = OSX::NSAttributedString.alloc.initWithData_options_documentAttributes_error_(data, null, null, outError)
It gives me this error:
2009-12-31 19:42:54.317 Ruby Text[3791:a0f] MyDocument#readFromData_ofType_error_: OSX::OCMessageSendException: Can't get Objective-C method signature for selector 'null' of receiver #<MyDocument:0x2aaa8a class='MyDocument' id=0x2770e20>
/Library/Frameworks/RubyCocoa.framework/Resources/ruby/osx/objc/oc_wrapper.rb:50:in `ocm_send'
/Library/Frameworks/RubyCocoa.framework/Resources/ruby/osx/objc/oc_wrapper.rb:50:in `method_missing'
/Users/myname/Documents/Ruby Text/build/Debug/Ruby Text.app/Contents/Resources/MyDocument.rb:44:in `readFromData_ofType_error_'
/Users/myname/Documents/Ruby Text/build/Debug/Ruby Text.app/Contents/Resources/rb_main.rb:22:in `NSApplicationMain'
/Users/myname/Documents/Ruby Text/build/Debug/Ruby Text.app/Contents/Resources/rb_main.rb:22
2009-12-31 19:42:54.320 Ruby Text[3791:a0f] HIToolbox: ignoring exception 'Can't get Objective-C method signature for selector 'null' of receiver #<MyDocument:0x2aaa8a class='MyDocument' id=0x2770e20>' that raised inside Carbon event dispatch
(
0 CoreFoundation 0x97b0940a __raiseError + 410
1 libobjc.A.dylib 0x943ff509 objc_exception_throw + 56
2 CoreFoundation 0x97b53a21 -[NSException raise] + 17
3 RubyCocoa 0x00010ddc rbobj_call_ruby + 764
4 RubyCocoa 0x0000dbda install_ovmix_methods + 2218
5 libffi.dylib 0x97bceb9f ffi_closure_SYSV_inner + 177
6 libffi.dylib 0x97bce9c2 ffi_closure_SYSV + 34
7 AppKit 0x9135aac0 -[NSDocument readFromURL:ofType:error:] + 743
8 AppKit 0x91247955 -[NSDocument initWithContentsOfURL:ofType:error:] + 311
9 AppKit 0x912474f9 -[NSDocumentController makeDocumentWithContentsOfURL:ofType:error:] + 383
10 AppKit 0x912472b1 -[NSDocumentController openDocumentWithContentsOfURL:display:error:] + 886
11 AppKit 0x912457bf -[NSDocumentController _openDocumentsWithContentsOfURLs:display:presentErrors:] + 169
12 AppKit 0x9135ee87 -[NSDocumentController openDocument:] + 352
13 AppKit 0x9103af86 -[NSApplication sendAction:to:from:] + 112
14 AppKit 0x9103ae39 -[NSMenuItem _corePerformAction] + 435
15 AppKit 0x9103ab2a -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 174
16 AppKit 0x9103aa16 -[NSMenu performActionForItemAtIndex:] + 65
17 AppKit 0x9103a9c9 -[NSMenu _internalPerformActionForItemAtIndex:] + 50
18 AppKit 0x9103a92f -[NSMenuItem _internalPerformActionThroughMenuIfPossible] + 97
19 AppKit 0x9103a873 -[NSCarbonMenuImpl _carbonCommandProcessEvent:handlerCallRef:] + 336
20 AppKit 0x9102ef79 NSSLMMenuEventHandler + 404
21 HIToolbox 0x97719e29 _ZL23DispatchEventToHandlersP14EventTargetRecP14OpaqueEventRefP14HandlerCallRec + 1567
22 HIToolbox 0x977190f0 _ZL30SendEventToEventTargetInternalP14OpaqueEventRefP20OpaqueEventTargetRefP14HandlerCallRec + 411
23 HIToolbox 0x9773b981 SendEventToEventTarget + 52
24 HIToolbox 0x97767e3b _ZL18SendHICommandEventmPK9HICommandmmhPKvP20OpaqueEventTargetRefS5_PP14OpaqueEventRef + 448
25 HIToolbox 0x9778cb20 SendMenuCommandWithContextAndModifiers + 66
26 HIToolbox 0x9778cad7 SendMenuItemSelectedEvent + 121
27 HIToolbox 0x9778c9d3 _ZL19FinishMenuSelectionP13SelectionDataP10MenuResultS2_ + 152
28 HIToolbox 0x9775c212 _ZL14MenuSelectCoreP8MenuData5PointdmPP13OpaqueMenuRefPt + 440
29 HIToolbox 0x9775b9a9 _HandleMenuSelection2 + 465
30 HIToolbox 0x9775b7c7 _HandleMenuSelection + 53
31 AppKit 0x910284ba _NSHandleCarbonMenuEvent + 285
32 AppKit 0x90ffd076 _DPSNextEvent + 2304
33 AppKit 0x90ffc306 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 156
34 AppKit 0x90fbe49f -[NSApplication run] + 821
35 AppKit 0x90fb6535 NSApplicationMain + 574
36 libffi.dylib 0x97bce91d ffi_call_SYSV + 29
37 libffi.dylib 0x97bcec49 ffi_call + 138
38 RubyCocoa 0x0001c94e rb_ffi_dispatch + 2558
39 RubyCocoa 0x0001554c find_bs_method + 1020
40 libruby.1.dylib 0x00044dfa rb_rescue + 800
41 libruby.1.dylib 0x0004fac0 rb_proc_call + 1452
42 libruby.1.dylib 0x000507db rb_proc_call + 4807
43 libruby.1.dylib 0x0004bb0c rb_provided + 7165
44 libruby.1.dylib 0x0005b83d rb_eval_string + 262
45 libruby.1.dylib 0x0005b86e ruby_exec + 22
46 libruby.1.dylib 0x0005b89a ruby_run + 42
47 RubyCocoa 0x00012931 RBApplicationMain + 337
48 Ruby Text 0x00001f4d main + 47
49 Ruby Text 0x00001ef2 start + 54
)
I tried everything (including nil, OSX::NULL, OSX::nil, null(), NULL, etc).
Can anyone help me? Thanks.
In RubyCocoa, a method will return the method's return value and then any double indirection arguments (source):
fileContents, docAttributes, error = OSX::NSAttributedString.alloc.initWithData_options_documentAttributes_error_(data, options)
In MacRuby, you need to create a pointer to an object and pass that to the method (source):
error = Pointer.new_with_type(‘#’)
NSFileManager.defaultManager.attributesOfItemAtPath path, error:error
Related
I'm working with Xcode 12.3 and MacOS 11.1.
A Textfield is embedded in a HStack and this one is embedded in a VStack.
struct ContentView: View {
#State var username: String = ""
var body: some View {
VStack {
HStack() {
Text("Enter Username:")
TextField("", text: $username)
}
Text("Your username: \(username)")
}
}
}
The code runs without any problems as an iOS-App.
However, compiling the code as a MacOS-App results in a runtime error.
2021-01-23 23:18:29.835048+0100 TestMacSwiftUI[6349:280606] [General] ERROR: Setting
<_TtC7SwiftUIP33_C58093E7172B0A541A997680E343D0D516_SystemTextField: 0x7fa1666294b0> as the first responder for window
<NSWindow: 0x7fa166606110>, but it is in a different window ((null))! This would eventually crash when the view is freed.
The first responder will be set to nil.
0 AppKit 0x00007fff22c5a499 -[NSWindow _validateFirstResponder:] + 449
1 AppKit 0x00007fff22c5a294 -[NSWindow _setFirstResponder:] + 31
2 AppKit 0x00007fff22d7e72b -[NSWindow _realMakeFirstResponder:] + 338
3 SwiftUI 0x00007fff42d8627b $s7SwiftUI11FocusBridgeC04moveC02toyAA0C4ItemV_tF + 155
4 SwiftUI 0x00007fff42d86fad $s7SwiftUI11FocusBridgeC27hostDidBecomeFirstResponder33_74086170859BF7C5D78394D4DEE7E0F9LLyyF + 861
5 SwiftUI 0x00007fff42d85b97 $s7SwiftUI11FocusBridgeC23firstResponderDidChange2to04rootF0ySo11NSResponderCSg_AA0F4Node_pSgtF + 583
6 SwiftUI 0x00007fff42c7102b $s7SwiftUI13NSHostingViewC12observeValue10forKeyPath2of6change7contextySSSg_ypSgSDySo05NSKeyf6ChangeH0aypGSgSvSgtFyycfU_ + 299
7 SwiftUI 0x00007fff42632c8c $sIeg_ytIegr_TR + 12
8 SwiftUI 0x00007fff42c79631 $sIeg_ytIegr_TRTA + 17
9 SwiftUI 0x00007fff42b61374 $s7SwiftUI6UpdateO3endyyFZ + 436
10 SwiftUI 0x00007fff42c70e85 $s7SwiftUI13NSHostingViewC12observeValue10forKeyPath2of6change7contextySSSg_ypSgSDySo05NSKeyf6ChangeH0aypGSgSvSgtF + 805
11 SwiftUI 0x00007fff42c71159 $s7SwiftUI13NSHostingViewC12observeValue10forKeyPath2of6change7contextySSSg_ypSgSDySo05NSKeyf6ChangeH0aypGSgSvSgtFTo + 249
12 Foundation 0x00007fff21188ab8 NSKeyValueNotifyObserver + 327
13 Foundation 0x00007fff2124fe45 NSKeyValueDidChange + 431
14 Foundation 0x00007fff212f0539 NSKeyValueDidChangeWithPerThreadPendingNotifications + 146
15 AppKit 0x00007fff22d7e72b -[NSWindow _realMakeFirstResponder:] + 338
16 AppKit 0x00007fff22d93adf -[NSWindow _selectFirstKeyView] + 758
17 AppKit 0x00007fff22d9310f -[NSWindow _setUpFirstResponder] + 189
18 AppKit 0x00007fff22d90577 -[NSWindow _doWindowWillBeVisibleAsSheet:] + 153
19 AppKit 0x00007fff22d8e4bd -[NSWindow _reallyDoOrderWindowAboveOrBelow:relativeTo:findKey:forCounter:force:isModal:] + 1317
20 AppKit 0x00007fff22d8dc42 -[NSWindow _reallyDoOrderWindow:relativeTo:findKey:forCounter:force:isModal:] + 135
21 AppKit 0x00007fff22d8cc52 -[NSWindow _doOrderWindow:relativeTo:findKey:forCounter:force:isModal:] + 289
22 AppKit 0x00007fff22d8cad0 -[NSWindow orderWindow:relativeTo:] + 155
23 AppKit 0x00007fff22d806f1 -[NSWindow makeKeyAndOrderFront:] + 60
24 TestMacSwiftUI 0x000000010e887d21 $s14TestMacSwiftUI11AppDelegateC29applicationDidFinishLaunchingyy10Foundation12NotificationVF + 3169
25 TestMacSwiftUI 0x000000010e887f62 $s14TestMacSwiftUI11AppDelegateC29applicationDidFinishLaunchingyy10Foundation12NotificationVFTo + 146
26 CoreFoundation 0x00007fff2041dfec __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
27 CoreFoundation 0x00007fff204b989b ___CFXRegistrationPost_block_invoke + 49
28 CoreFoundation 0x00007fff204b980f _CFXRegistrationPost + 454
29 CoreFoundation 0x00007fff203eebde _CFXNotificationPost + 723
30 Foundation 0x00007fff2115dabe -[NSNotificationCenter postNotificationName:object:userInfo:] + 59
31 AppKit 0x00007fff22c4cf6d -[NSApplication _postDidFinishNotification] + 305
32 AppKit 0x00007fff22c4ccbb -[NSApplication _sendFinishLaunchingNotification] + 208
33 AppKit 0x00007fff22c49eb2 -[NSApplication(NSAppleEventHandling) _handleAEOpenEvent:] + 541
34 AppKit 0x00007fff22c49b07 -[NSApplication(NSAppleEventHandling) _handleCoreEvent:withReplyEvent:] + 665
35 Foundation 0x00007fff21189056 -[NSAppleEventManager dispatchRawAppleEvent:withRawReply:handlerRefCon:] + 308
36 Foundation 0x00007fff21188ec6 _NSAppleEventManagerGenericHandler + 80
37 AE 0x00007fff26201ed9 _AppleEventsCheckInAppWithBlock + 15850
38 AE 0x00007fff262015f4 _AppleEventsCheckInAppWithBlock + 13573
39 AE 0x00007fff261fa260 aeProcessAppleEvent + 452
40 HIToolbox 0x00007fff286bd612 AEProcessAppleEvent + 54
41 AppKit 0x00007fff22c44276 _DPSNextEvent + 2048
42 AppKit 0x00007fff22c425af -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1366
43 AppKit 0x00007fff22c34b0a -[NSApplication run] + 586
44 AppKit 0x00007fff22c08df2 NSApplicationMain + 816
45 TestMacSwiftUI 0x000000010e8882d4 $sSo21NSApplicationDelegateP6AppKitE4mainyyFZ + 36
46 TestMacSwiftUI 0x000000010e88829e $s14TestMacSwiftUI11AppDelegateC5$mainyyFZ + 46
47 TestMacSwiftUI 0x000000010e888309 main + 41
48 libdyld.dylib 0x00007fff2034b621 start + 1
49 ??? 0x0000000000000003 0x0 + 3
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)
I have a Xamarin.Mac app that crashes when trying to display an alert from the GetView method of a NSOutlineViewDelegate.
The code is the following:
internal class ItemsDelegate : NSOutlineViewDelegate
{
public override NSView GetView(NSOutlineView outlineView, NSTableColumn tableColumn, NSObject item)
{
try
{
//code to return the NSView
}
catch (Exception ex)
{
NSAlert alert = new NSAlert();
alert.InformativeText = message;
alert.RunModal();
}
}
}
So, what it happens is that a controlled exception is thrown in the code to return the NSView.
When trying to show it with the NSAlert, in the catch block and the "alert.RunModal()" is executed, the app crashes.
The crash exception is the following:
Terminating app due to uncaught exception 'NSGenericException', reason: '-[NSAlert runModal] may not be invoked inside of transaction commit (usually this means it was invoked inside of a view's -drawRect: method.)'
First throw call stack:
(
0 CoreFoundation 0x00007fffca9976fb _exceptionPreprocess + 171
1 libobjc.A.dylib 0x00007fffdf33ba2a objc_exception_throw + 48
2 CoreFoundation 0x00007fffcaa149a5 +[NSException raise:format:] + 197
3 AppKit 0x00007fffc8d2eeaa _NSRunModal + 266
4 AppKit 0x00007fffc876c591 -[NSAlert runModal] + 270
5 macplastic 0x0000000107c97b39 xamarin_dyn_objc_msgSend + 217
6 ??? 0x0000000116c14f2b 0x0 + 4676734763
7 ??? 0x0000000116b06825 0x0 + 4675627045
8 ??? 0x0000000116a62808 0x0 + 4674955272
9 ??? 0x0000000116a62b8e 0x0 + 4674956174
10 macplastic 0x0000000107d9a340 mono_jit_runtime_invoke + 2272
11 macplastic 0x0000000107e4b3c8 do_runtime_invoke + 88
12 macplastic 0x0000000107e4b2d6 mono_runtime_invoke + 102
13 macplastic 0x0000000107c9583d xamarin_invoke_trampoline + 5725
14 macplastic 0x0000000107c965bd xamarin_arch_trampoline + 189
15 macplastic 0x0000000107c979b1 xamarin_x86_64_common_trampoline + 110
16 AppKit 0x00007fffc85b4f84 -[NSTableView(NSTableViewViewBased) makeViewForTableColumn:row:] + 76
17 AppKit 0x00007fffc85b495b -[NSTableRowData _addViewToRowView:atColumn:row:] + 308
18 AppKit 0x00007fffc85b469f -[NSTableRowData _addViewsToRowView:atRow:] + 204
19 AppKit 0x00007fffc85b2e47 -[NSTableRowData _initializeRowView:atRow:] + 390
20 AppKit 0x00007fffc85b144d -[NSTableRowData _addRowViewForVisibleRow:withPriorView:] + 398
21 AppKit 0x00007fffc85b1208 -[NSTableRowData _addRowViewForVisibleRow:withPriorRowIndex:inDictionary:withRowAnimation:] + 316
22 AppKit 0x00007fffc85b0030 -[NSTableRowData _unsafeUpdateVisibleRowEntries] + 1647
23 AppKit 0x00007fffc85af923 -[NSTableRowData updateVisibleRowViews] + 232
24 AppKit 0x00007fffc85af27a -[NSTableView layout] + 178
25 AppKit 0x00007fffc8d19afc _NSViewLayout + 450
26 AppKit 0x00007fffc8550074 -[NSView _doLayout] + 126
27 AppKit 0x00007fffc854fbf9 -[NSView _layoutSubtreeWithOldSize:] + 497
28 AppKit 0x00007fffc854fec7 -[NSView _layoutSubtreeWithOldSize:] + 1215
29 AppKit 0x00007fffc854fec7 -[NSView _layoutSubtreeWithOldSize:] + 1215
30 AppKit 0x00007fffc854fec7 -[NSView _layoutSubtreeWithOldSize:] + 1215
31 AppKit 0x00007fffc854fec7 -[NSView _layoutSubtreeWithOldSize:] + 1215
32 AppKit 0x00007fffc854fec7 -[NSView _layoutSubtreeWithOldSize:] + 1215
33 AppKit 0x00007fffc854fec7 -[NSView _layoutSubtreeWithOldSize:] + 1215
34 AppKit 0x00007fffc854fec7 -[NSView _layoutSubtreeWithOldSize:] + 1215
35 AppKit 0x00007fffc8d1fe89 -[NSView _layoutSubtreeIfNeededAndAllowTemporaryEngine:] + 1517
36 AppKit 0x00007fffc856e3f1 -[NSWindow(NSConstraintBasedLayout) _layoutViewTree] + 163
37 AppKit 0x00007fffc85dd52a -[NSWindow(NSConstraintBasedLayout) layoutIfNeeded] + 269
38 AppKit 0x00007fffc8d49f78 _NSWindowGetDisplayCycleObserver_block_invoke.6213 + 67
39 AppKit 0x00007fffc85eec89 _37+[NSDisplayCycle currentDisplayCycle]_block_invoke + 454
40 QuartzCore 0x00007fffd045a1ba _ZN2CA11Transaction19run_commit_handlersE18CATransactionPhase + 46
41 QuartzCore 0x00007fffd0561e10 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 160
42 QuartzCore 0x00007fffd0458d55 _ZN2CA11Transaction6commitEv + 475
43 AppKit 0x00007fffc88d0d99 _37+[NSDisplayCycle currentDisplayCycle]_block_invoke.31 + 323
44 CoreFoundation 0x00007fffca92dec7 _CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
45 CoreFoundation 0x00007fffca92de37 _CFRunLoopDoObservers + 391
46 CoreFoundation 0x00007fffca90ed79 _CFRunLoopRun + 873
47 CoreFoundation 0x00007fffca90e7b4 CFRunLoopRunSpecific + 420
48 HIToolbox 0x00007fffc9e9e2ac RunCurrentEventLoopInMode + 240
49 HIToolbox 0x00007fffc9e9e0e1 ReceiveNextEventCommon + 432
50 HIToolbox 0x00007fffc9e9df16 _BlockUntilNextEventMatchingListInModeWithFilter + 71
51 AppKit 0x00007fffc84a06cd _DPSNextEvent + 1093
52 AppKit 0x00007fffc8c17830 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 2730
53 AppKit 0x00007fffc849506d -[NSApplication run] + 926
54 AppKit 0x00007fffc845f983 NSApplicationMain + 1237
55 ??? 0x000000010c7cc9d2 0x0 + 4504472018
56 ??? 0x000000010c7cc5cd 0x0 + 4504470989
57 macplastic 0x0000000107d9a340 mono_jit_runtime_invoke + 2272
58 macplastic 0x0000000107e4b3c8 do_runtime_invoke + 88
59 macplastic 0x0000000107e4d8a0 mono_runtime_exec_main + 896
60 macplastic 0x0000000107e4d45d mono_runtime_run_main + 909
61 macplastic 0x0000000107cefca7 mono_jit_exec + 247
62 macplastic 0x0000000107cf2022 mono_main + 8098
63 macplastic 0x0000000107c982c4 xamarin_main + 980
64 macplastic 0x0000000107c98fd4 main + 36
65 macplastic 0x0000000107c7f944 start + 52
66 ??? 0x0000000000000002 0x0 + 2
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Any help?
Also, why does the app crash even if you add a try/catch block?? Is there any way to avoid the crash??
try
{
NSAlert alert = new NSAlert();
alert.InformativeText = message;
alert.RunModal();
}
catch (Exception ex)
{
//Nothing to do, we did our best to show the error message, avoid an unhandled crash.
}
Any help would be much appreciated.
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.
I'm testing Swift in a simple Mac app. I got a NSToolbar in Storyboard and draw a NSSearchfield inside. The NSSearchfiled is connected to the First Responder's method controlTextDidChange (the first responder is the ViewController where I added NSTextFieldDelegate).
This is the method:
#IBAction override func controlTextDidChange(obj: NSNotification!) {
println("searching...")
println(obj.object.stringValue)
}
The method gets correctly called every time a new character is searched and the app does not crash however what's being returned is the following:
searching...
2014-08-03 09:56:57.770 TestApp[1129:24219] -[NSSearchField object]: unrecognized selector sent to instance 0x6080001a07e0
2014-08-03 09:56:57.770 TestApp[1129:24219] -[NSSearchField object]: unrecognized selector sent to instance 0x6080001a07e0
2014-08-03 09:56:57.775 TestApp[1129:24219] (
0 CoreFoundation 0x00007fff92e6af1c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff930ae74e objc_exception_throw + 43
2 CoreFoundation 0x00007fff92e6de4d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00007fff92db63c4 ___forwarding___ + 1028
4 CoreFoundation 0x00007fff92db5f38 _CF_forwarding_prep_0 + 120
5 TestApp 0x000000010000c187 _TFC9TestApp14ViewController20controlTextDidChangefS0_FGSQCSo14NSNotification_T_ + 231
6 TestApp 0x000000010000c582 _TToFC9TestApp14ViewController20controlTextDidChangefS0_FGSQCSo14NSNotification_T_ + 66
7 libsystem_trace.dylib 0x00007fff9117bc07 _os_activity_initiate + 75
8 AppKit 0x00007fff8d52b168 -[NSApplication sendAction:to:from:] + 410
9 AppKit 0x00007fff8d52af90 -[NSControl sendAction:to:] + 86
10 AppKit 0x00007fff8d6faf91 __26-[NSCell _sendActionFrom:]_block_invoke + 131
11 libsystem_trace.dylib 0x00007fff9117bc07 _os_activity_initiate + 75
12 AppKit 0x00007fff8d57329e -[NSCell _sendActionFrom:] + 144
13 AppKit 0x00007fff8d92fe8f __64-[NSSearchFieldCell(NSSearchFieldCell_Local) _sendPartialString]_block_invoke + 63
14 libsystem_trace.dylib 0x00007fff9117bc07 _os_activity_initiate + 75
15 AppKit 0x00007fff8d92fe47 -[NSSearchFieldCell(NSSearchFieldCell_Local) _sendPartialString] + 186
16 Foundation 0x00007fff932ee3d3 __NSFireTimer + 95
17 CoreFoundation 0x00007fff92dbf464 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
18 CoreFoundation 0x00007fff92dbf0f3 __CFRunLoopDoTimer + 1059
19 CoreFoundation 0x00007fff92e320fd __CFRunLoopDoTimers + 301
20 CoreFoundation 0x00007fff92d7b4d2 __CFRunLoopRun + 2018
21 CoreFoundation 0x00007fff92d7aaa8 CFRunLoopRunSpecific + 296
22 HIToolbox 0x00007fff90adcaff RunCurrentEventLoopInMode + 235
23 HIToolbox 0x00007fff90adc872 ReceiveNextEventCommon + 431
24 HIToolbox 0x00007fff90adc6b3 _BlockUntilNextEventMatchingListInModeWithFilter + 71
25 AppKit 0x00007fff8d35c2a5 _DPSNextEvent + 1000
26 AppKit 0x00007fff8d35ba79 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 139
27 AppKit 0x00007fff8d34fad3 -[NSApplication run] + 594
28 AppKit 0x00007fff8d33b2de NSApplicationMain + 1778
29 TestApp 0x000000010000da72 top_level_code + 34
30 TestApp 0x000000010000daaa main + 42
31 libdyld.dylib 0x00007fff8cb765c9 start + 1
32 ??? 0x0000000000000003 0x0 + 3
)
I can't figure out where the "unrecognized selector sent to instance" comes from.
controlTextDidChange method expects NSSearchField!, not NSNotification!.
Replace
#IBAction override func controlTextDidChange(obj: NSNotification!) {
println("searching...")
println(obj.object.stringValue)
}
with
#IBAction override func controlTextDidChange(obj: NSSearchField!) {
println("searching...")
println(obj.stringValue)
}
Solved by defining a custom method
#IBAction func controlTextDidChange_Custom(obj: NSSearchField!) {
if (!obj.stringValue.isEmpty) {
println("Searched: \(obj.stringValue)")
} else {
println("EMPTY")
}
}