AVMIDIPlayer.play() function crashes on iOS 18

It's only occurs on iOS 18+. Backtrace attached below.

Exception Codes: 0x0000000000000000, 0x0000000000000000
Termination Reason: SIGNAL 6 Abort trap: 6
Terminating Process: NoteKeys [24384]

Triggered by Thread:  0

Last Exception Backtrace:
0   CoreFoundation                	0x1a2d4c7cc __exceptionPreprocess + 164 (NSException.m:249)
1   libobjc.A.dylib               	0x1a001f2e4 objc_exception_throw + 88 (objc-exception.mm:356)
2   CoreFoundation                	0x1a2e47748 +[NSException raise:format:] + 128 (NSException.m:0)
3   AVFAudio                      	0x1bd41f4c8 -[AVMIDIPlayer play:] + 300 (AVMIDIPlayer.mm:145)
4   NoteKeys                      	0x1023c0670 SoundGenerator.playData() + 20 (SoundGenerator.swift:170)
5   NoteKeys                      	0x1023c0670 EditViewController.playBtnTapped(startIndex:) + 940 (EditViewController.swift:2034)
6   NoteKeys                      	0x1024497fc specialized Keyboard.playBtnTapped(sender:) + 1904 (Keyboard.swift:1249)
7   NoteKeys                      	0x10244631c Keyboard.playBtnTapped(sender:) + 4 (<compiler-generated>:0)
8   NoteKeys                      	0x10244631c @objc Keyboard.playBtnTapped(sender:) + 48
9   UIKitCore                     	0x1a58739cc -[UIApplication sendAction:to:from:forEvent:] + 100 (UIApplication.m:5816)
10  UIKitCore                     	0x1a58738a4 -[UIControl sendAction:to:forEvent:] + 112 (UIControl.m:942)
11  UIKitCore                     	0x1a58736f4 -[UIControl _sendActionsForEvents:withEvent:] + 324 (UIControl.m:1013)
12  UIKitCore                     	0x1a5fe8d8c -[UIButton _sendActionsForEvents:withEvent:] + 124 (UIButton.m:4198)
13  UIKitCore                     	0x1a5fea5a0 -[UIControl touchesEnded:withEvent:] + 400 (UIControl.m:692)
14  UIKitCore                     	0x1a57bb9ac -[UIWindow _sendTouchesForEvent:] + 852 (UIWindow.m:3318)
15  UIKitCore                     	0x1a57bb3d8 -[UIWindow sendEvent:] + 2964 (UIWindow.m:3641)
16  UIKitCore                     	0x1a564fb70 -[UIApplication sendEvent:] + 376 (UIApplication.m:12972)
17  UIKitCore                     	0x1a565009c __dispatchPreprocessedEventFromEventQueue + 1048 (UIEventDispatcher.m:2686)
18  UIKitCore                     	0x1a5659f3c __processEventQueue + 5696 (UIEventDispatcher.m:3044)
19  UIKitCore                     	0x1a5552c60 updateCycleEntry + 160 (UIEventDispatcher.m:133)
20  UIKitCore                     	0x1a55509d8 _UIUpdateSequenceRun + 84 (_UIUpdateSequence.mm:136)
21  UIKitCore                     	0x1a5550628 schedulerStepScheduledMainSection + 172 (_UIUpdateScheduler.m:1171)
22  UIKitCore                     	0x1a555159c runloopSourceCallback + 92 (_UIUpdateScheduler.m:1334)
23  CoreFoundation                	0x1a2d20328 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28 (CFRunLoop.c:1970)
24  CoreFoundation                	0x1a2d202bc __CFRunLoopDoSource0 + 176 (CFRunLoop.c:2014)
25  CoreFoundation                	0x1a2d1ddc0 __CFRunLoopDoSources0 + 244 (CFRunLoop.c:2051)
26  CoreFoundation                	0x1a2d1cfbc __CFRunLoopRun + 840 (CFRunLoop.c:2969)
27  CoreFoundation                	0x1a2d1c830 CFRunLoopRunSpecific + 588 (CFRunLoop.c:3434)
28  GraphicsServices              	0x1eecfc1c4 GSEventRunModal + 164 (GSEvent.c:2196)
29  UIKitCore                     	0x1a5882eb0 -[UIApplication _run] + 816 (UIApplication.m:3844)
30  UIKitCore                     	0x1a59315b4 UIApplicationMain + 340 (UIApplication.m:5496)
31  NoteKeys                      	0x10254bc10 main + 68 (AppDelegate.swift:15)
32  dyld                          	0x1c870aec8 start + 2724 (dyldMain.cpp:1334)

Thanks very much for any help: )

Thanks for your post. Apologies for the delay.

Kindly submit a comprehensive crash report, adhering to the guidelines outlined in Posting a Crash Report.

https://developer.apple.com/forums/thread/688669

However based on what you posted, it seems like the issue is on the 3rd party framework or app code itself as is not clear on the crash posted "NoteKeys" (could be the app name or a 3rd party)

It seems by this line is the app: NoteKeys 0x10254bc10 main + 68 (AppDelegate.swift:15)

I would take a look at this line of code (SoundGenerator.swift:170) and put a breakpoint and see how it crashes there before playing the [AVMIDIPlayer play:]

However is hard to see based on the post. I would recommend to post the crash report on raw format. Can you crash it on Xcode?

Albert Pascual
  Worldwide Developer Relations.

AVMIDIPlayer.play() function crashes on iOS 18
 
 
Q