I have a photo editing app which uses a simple Metal Render to display CIFilter output images. It works just fine in Swift 5 but in Swift 6 it crashes on starting the Metal command buffer with an error in the Queue : com.Metal.CompletionQueueDispatch (serial). (Screen shot below)
The crash is occurring before I can debug.. I changed the command buffer to report
MTLCommandBufferDescriptorStatus errorOptions = .encoderExecutionStatus.
No luck with getting insight into the source of the crash..
Likewise the error is happening before any of the usual Metal debug tools are enabled.
The Metal render works just fine in Swift 5 and also works fine with almost of of the Swift Compiler Upcoming feature flags are set to Yes. [The "Default Internal Imports" flag is still No. (the number of compile errors with this setting is absolutely scary! but that's another topic)}
Do you have any suggestions on debugging or ideas on why the Metal library is crashing in Swift 6.
Everything is current release versions and hardware.
It’s hard to say exactly what’s going on here but the fact that frame 0 is _dispatch_assert_queue_fail suggests that the Swift 6 compiler has inserted an assert that your code is running in the correct isolation context and that assert has failed. This is a common pitfall. Technically the compiler is saving your from yourself, but resolving the issue can be tricky.
I recently discussed this, in a very different context, on DevForums. See this post.
If you post a complete crash report, I might be able to offer further suggestions. For info on posting crash reports, see Posting a Crash Report. Well, that info is for DevForums, but much of the same logic applies here as well. In the case of Swift Forums, use the Hide Details button in the editor to avoid clogging up the thread.
Quinn - Gold star for your extended explanation in the Developer Forum thread! Trying one of the suggestions worked and the app is now on Swift 6 !
I used the @Sendable for the metal command queue command buffer as follows
commandBuffer.addCompletedHandler { @Sendable (_ commandBuffer)-> Swift.Void in ....
Thanks so much !!
Also -
The compiler team should consider adding information that can be used for correcting the problem. Right now the assert crash is completely cryptic to me and has no usable information about the cause.
The compiler team should consider adding information that can
be used for correcting the problem.
The compiler folks are very interested in improving the diagnostics. I’m not sure how feasible it is to do in this specific case, but it’s probably worth filing a bug outlining your experience and what you’d like to see improve.