App crashing on macOS 27

My app is now crashing when clicking on the tray icon with macOS 27 when it worked just fine with previous releases. I've submitted a feedback issue, FB23457330, but was curious if this should be something I should be looking into.

Thread backtrace is

Thread 9 Crashed::  Dispatch queue: com.apple.root.utility-qos.cooperative
0   libsystem_kernel.dylib        	       0x18539a654 __pthread_kill + 8
1   libsystem_pthread.dylib       	       0x1853d6970 pthread_kill + 296
2   libsystem_c.dylib             	       0x1852d8b4c abort + 148
3   libc++abi.dylib               	       0x18538d2ec __abort_message + 132
4   libc++abi.dylib               	       0x18537a640 demangling_terminate_handler() + 296
5   libobjc.A.dylib               	       0x184f6e3cc _objc_terminate() + 156
6   libc++abi.dylib               	       0x18538a288 std::__terminate(void (*)()) + 16
7   libc++abi.dylib               	       0x18538c79c __cxxabiv1::failed_throw(__cxxabiv1::__cxa_exception*) + 88
8   libc++abi.dylib               	       0x18537918c __cxa_throw + 92
9   libobjc.A.dylib               	       0x184f648f0 objc_exception_throw + 448
10  Foundation                    	       0x186c6e858 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 288
11  AppKit                        	       0x1899a6cfc -[NSMenu itemArray] + 32
12  AppKit                        	       0x18a0987fc -[NSMenu _campoItem] + 24
13  AppKit                        	       0x18a09831c -[NSMenu _assistantFieldIsEffectivelyVisible] + 24
14  AppKit                        	       0x18a09d970 -[NSMenu _effectiveTypingBehavior] + 60
15  AppKit                        	       0x189f1a7d0 -[NSContextMenuImpl _targetWidth] + 164
16  AppKit                        	       0x189f1afe4 -[NSContextMenuImpl _commitWindowSizeChangesForWidth:height:animated:] + 96
17  AppKit                        	       0x189f21880 -[NSContextMenuImpl _updateSizeEstimateForItemAtIndex:includingHeight:] + 1556
18  AppKit                        	       0x189f1f8dc -[NSContextMenuImpl _menuItem:atIndex:didChangeTitleFrom:to:] + 260
19  AppKit                        	       0x1899acf38 -[NSMenu _menuItem:didChangeTitleFrom:to:] + 124
20  AppKit                        	       0x1899a9cb4 -[NSMenuItem setTitle:] + 160
21  NCXClient                     	       0x100061438 0x100018000 + 300088
22  NCXClient                     	       0x10006bc95 0x100018000 + 343189
23  NCXClient                     	       0x10003c909 0x100018000 + 149769
24  NCXClient                     	       0x10004d3b9 0x100018000 + 218041
25  NCXClient                     	       0x10003c909 0x100018000 + 149769
26  libswift_Concurrency.dylib    	       0x2acf59d41 completeTaskWithClosure(swift::AsyncContext*, swift::SwiftError*) + 1
Answered by galad87 in 896001022

UI changes are supposed to run on the main thread, you are modifying a NSMenu on a background thread, try to run that code on the main thread.

Accepted Answer

UI changes are supposed to run on the main thread, you are modifying a NSMenu on a background thread, try to run that code on the main thread.

Is this something that is new in macOS27? It's been this way for over 2yrs with zero issues.

Thanks for this interesting thread.

In older versions of macOS, modifying this specific property on a background thread resulted in "undefined behavior." It might have silently worked, caused occasional visual glitches, or leaked memory, but it didn't strictly crash, however you should see warnings in the console.

With very few exceptions, all interactions with UI elements like NSMenu and NSMenuItem must occur on the main thread. Any UI changes should be on the main thread. Since your backtrace shows you are using Swift Concurrency, you need to ensure that the code updating the NSMenuItem is routed to the Main Actor.

To catch these issues early before they crash in production, you can enable the Main Thread Checker in Xcode. Go to Product > Scheme > Edit Scheme... > Run > Diagnostics and check the box for "Main Thread Checker". This will immediately flag any background UI updates during development.

Hope this helps.

Albert  WWDR

App crashing on macOS 27
 
 
Q