[quote='796453022, DTS Engineer, /thread/760029?answerId=796453022#796453022']
This shows how the ns as! [MyElement] cast is done lazily
[/quote]
Thanks, this already helped me reproduce and fix the second crash. The array was coming from a token field's objectValue.
Regarding the first crash, I noticed something strange. The crash report seems to imply that a particular method called another one, which is impossible. Let me show and explain to you the rest of the stacktrace:
...
Code Type: ARM-64
Parent Process: launchd [1]
User ID: 501
Date/Time: 2024-07-18 14:59:40.4375 +0800
OS Version: macOS 15.0 (24A5289h)
...
Crashed Thread: 0
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x00000001045048b8
Termination Reason: Namespace SIGNAL, Code 5 Trace/BPT trap: 5
Terminating Process: exc handler [1771]
Thread 0 Crashed:
0 MyApp 0x00000001045048b8 specialized Collection.map<A>(_:) + 596
1 MyApp 0x00000001045011e4 MyViewController.validateToolbarButtons() + 648 (MyViewController.swift:742)
...
12 MyApp 0x00000001044fcef4 MyViewController.myOtherAction(_:) + 184 (MyViewController.swift:455)
13 MyApp 0x00000001044fff28 @objc MyViewController.myModalAction(_:) + 80
14 AppKit 0x000000019e2ae13c -[NSApplication(NSResponder) sendAction:to:from:] + 460
15 AppKit 0x000000019e375b08 -[NSMenuItem _corePerformAction] + 372
16 AppKit 0x000000019ea4be30 _NSMenuPerformActionWithHighlighting + 152
17 AppKit 0x000000019e3ad5d0 -[NSMenu performActionForItemAtIndex:] + 200
18 AppKit 0x000000019e3ad4f0 -[NSMenu _internalPerformActionForItemAtIndex:] + 76
19 AppKit 0x000000019ea4204c +[NSCocoaMenuImpl _performActionForMenuItem:] + 176
20 AppKit 0x000000019e84ff58 -[NSMenuTrackingSession _performPostTrackingDismissalActions] + 268
21 AppKit 0x000000019e84fc60 -[NSMenuTrackingSession startRunningMenuEventLoop:] + 1332
22 AppKit 0x000000019e84f6d0 -[NSMenuTrackingSession startMonitoringEvents:] + 256
23 AppKit 0x000000019efe5d78 -[NSContextMenuTrackingSession startMonitoringEvents:] + 144
24 AppKit 0x000000019e8048f8 +[NSContextMenuImpl presentPopup:fromView:withContext:animated:] + 848
25 AppKit 0x000000019ea4d5ec _NSPopUpMenu + 2128
26 AppKit 0x000000019ea51cbc -[NSCocoaMenuImpl _popUpContextMenu:withEvent:forView:withFont:] + 304
27 AppKit 0x000000019e429acc -[NSMenu _popUpContextMenu:withEvent:forView:withFont:] + 208
28 AppKit 0x000000019ece4658 -[NSView _showMenuForEvent:] + 72
29 AppKit 0x000000019e425ff4 -[NSView rightMouseDown:] + 76
30 AppKit 0x000000019e7225e0 -[NSControl _rightMouseUpOrDown:] + 352
31 AppKit 0x000000019ed81ec4 _routeRightMouseDownEvent + 264
32 AppKit 0x000000019e2348f8 -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 420
33 AppKit 0x000000019e234584 -[NSWindow(NSEventRouting) sendEvent:] + 284
34 AppKit 0x000000019ea1f568 -[NSApplication(NSEventRouting) sendEvent:] + 1656
35 AppKit 0x000000019e632b78 -[NSApplication _handleEvent:] + 60
36 AppKit 0x000000019e100914 -[NSApplication run] + 520
37 AppKit 0x000000019e0d7094 NSApplicationMain + 888
38 MyApp 0x000000010446ca80 main + 128 (main.swift:12)
39 dyld 0x000000019a16b274 start + 2840
The ellipsis only hides methods from my own classes. Directly below it, it would seem that @objc MyViewController.myModalAction(_:), which shows an app modal window, somehow calls MyViewController.myOtherAction(_:), but myOtherAction can only be called by a menu or the press of a toolbar button which are both disabled by the modal window shown by myModalAction. Does this mean that myOtherAction is called somehow when the modal window opened by myModalAction is closed?
Another interesting point: I don't know why myModalAction is prefixed with @objc, since both are declared as @IBAction func methodName(_ sender: Any). The only difference is that myModalAction is set as a table view's doubleAction, but from the rest of the stacktrace it seems like myModalAction is called by a menu.