Crash on iOS18 Beta5 when adding a SCNAnimation animationDidStop closure with Swift6 selected

I'm trying to update my projects to use Swift6, if I change the project settings to use Swift6 then my app crashes when I add a closure to the SCNAnimation animationDidStop property. The error is inside the SceneKit renderingQueue and indicates that the callback is being called on the wring queue.

Maybe I need to do something in the code to fix this but I can't seem to make it work, maybe a SceneKit bug?

If you create a new game template in Xcode using SceneKit and replace the contents of GameViewController.swift with the following you will see the app crash after it is launched.

import UIKit
import SceneKit

class GameViewController: UIViewController {

  let player: SCNAnimationPlayer = {
    let a = CABasicAnimation(keyPath: "opacity")
    return SCNAnimationPlayer(animation: SCNAnimation(caAnimation: a))
  }()

  override func viewDidLoad() {
    super.viewDidLoad()

    let scnView = self.view as! SCNView
    scnView.scene = SCNScene()

    // Change the project settings to use Swift6
    // Setting this closure will then cause a _dispatch_assert_queue_fail
    // EXC_BREAKPOINT error in the scenekit.renderingQueue.SCNView queue,
    // the only thing on the stack is:
    // "%sBlock was %sexpected to execute on queue [%s (%p)]"
    player.animation.animationDidStop = { (a: SCNAnimation, b: SCNAnimatable, c: Bool) in
      print("stopped")
    }
    scnView.scene?.rootNode.addAnimationPlayer(player, forKey: nil)
    player.play()
  }

}

Thanks for reporting this issue with Xcode 16 beta 5. Could you please report the bug? Don’t forget to include the crash file in this post as well as the description of the bug.

Once you open the bug report, please post the FB number here for my reference. If you have any questions about filing a bug report, take a look at Bug Reporting: How and Why?

I get the same problem in multiple other places for example just running an SCNAction and having a completion handler also throws an error inside SceneKit, it seems like SceneKit is completely unusable with Swift6 enabled, I'm not sure how it can be so broken unless I'm doing something wrong, very frustrating.

Crash on iOS18 Beta5 when adding a SCNAnimation animationDidStop closure with Swift6 selected
 
 
Q