macossprite-kit

SpriteKit animations freeze in second window on second display on Apple Silicon


We have a 2023 Mac mini with an Apple M2 Pro chip. The Mac has two displays connected. If a SpriteKit application has two windows on separate desktops, one of the windows can’t run animations.

You can easily replicate this issue with the following steps:

  1. Create a new macOS project in Xcode.
  2. Select the sample Game project with SpriteKit as the technology.
  3. Edit the fade duration in GameScene.swift to make the animated nodes live longer (e.g. 15 seconds).
  4. In AppDelegate.applicationDidFinishLaunching, add code to instantiate a second window:
        let mainStoryboard = NSStoryboard.init(name: NSStoryboard.Name("Main"), bundle: nil)
        if let newWindow = mainStoryboard.instantiateInitialController() as? NSWindowController {
            newWindow.showWindow(self)
        }

  1. Run the app. If both windows are on the same desktop, animations run correctly. If the windows are on separate desktops, then animations halt on one of the desktops, even though the SKView reports full frame rate.

You can also just check out the sample project from my github repo: https://github.com/lanephillips/SKTest

The issue does not occur if the application is built for Intel processors only and run on Apple Silicon under Rosetta.

We've seen this issue occur in both macOS 13 and 14. I've filed a report through Feedback Assistant, but I'm posting here in case someone else has seen this and has a workaround.


Solution

  • I discovered today that if both displays are set to the same refresh rate then the bug does not occur. This is an acceptable workaround for us.

    I'm guessing that SpriteKit matches its own frame rate to one of the displays. If the rate for the other display doesn't match, then SpriteKit just gives up. I anticipate this is an "optimization" that Apple is going to flag as WONTFIX. It's strange, though, that this runs better as an Intel build on Rosetta.