Metal API error while debugging on iPhone 7

Hi, I getting this error when running the Mr.Pig app at the end of Chapter 19:

2016-10-29 11:46:20.267829 Mr.Pig[295:7410] XPC connection interrupted
/BuildRoot/Library/Caches/com.apple.xbs/Sources/Metal/Metal-85.83/ToolsLayers/Debug/MTLDebugRenderCommandEncoder.mm:946: failed assertion `For color attachment 0, the render pipeline’s pixelFormat (MTLPixelFormatRGBA8Unorm_sRGB) does not match the framebuffer’s pixelFormat (MTLPixelFormatBGR10_XR_sRGB).’

This error is only seen while Xcode is attached to the app running on my iPhone 7, which is running iOS 10.1. I am using Xcode 8.1. Interestingly, the app does not crash when just running on the device without Xcode attached. The error is seen when I tap on the splash scene and trigger the SKTransition to reveal the gameScene.

Googling has so far not turned up anything. Appreciate it if anyone has any ideas.

Thanks,
Tom

1 Like

I suspect this is most likely due to my having installed Xcode 7, 8, 8.1 Beta, and then 8.1 on my MacBook. I doubt it’s an issue with the content of the book.

Did you manage to fix this? I’m running into the same error.

Oh, sorry for not following up here. I did not find a resolution, and I now no longer believe it is due to having different versions of Xcode installed. The issue only happens when debugging code running on my iPhone 7. It did not occur when debugging code on my iPad mini 2, which was also running 10.1. Additionally, it has something do with using the SKTransition to switch scenes. I modified the Mr.Pig app to not use SKTransition, and to just switch the .scene property on the SCNView, and the error did not occur. I even created a new project that switched scenes using SKTransition and I saw the same error.

I think it’s a bug somewhere in Apple’s APIs, so I filed a radar. I haven’t heard anything on it yet.

2 Likes

Thanks for your reply! Removing the transition also made the error go away for me. It’s a workaround, but fine for me for now. Thanks a lot!

Glad to hear it. By the way: Apple closed my bug this morning as a duplicate of an existing bug. It sounds like they are aware of the issue. Hopefully it will be fixed in the near future.

Thank you. I already wanted to leave SceneKit and switch to Unreal Engine after this error :slight_smile:

As you commented, this only crashes when debugging through Xcode so the transitions will work correctly in your Release build. The downside of this solution is that your release code won’t ever be run/tested when you debug your app.

I added this build setting:

//:configuration = Debug
OTHER_SWIFT_FLAGS = -DDEBUG

//:completeSettings = none

And then modified the code like this to allow the transition to work when not debugging:

#if DEBUG

scnView.scene = gameScene
game.state = .playing
setupSounds()
gameScene.isPaused = false

#else

let transition = SKTransition.reveal(with: .up, duration: 1.0)

scnView.present(gameScene, with: transition, incomingPointOfView: nil,
                completionHandler: {
					self.game.state = .playing
					self.setupSounds()
					self.gameScene.isPaused = false
})

#endif

1 Like

I just thought I’d add that this seem to have something to do with the wide color gamut of the iPhone 7 and iPad pro 9.7". MTLPixelFormatBGR10_XR_sRGB is one of the new pixel formats used on those devices. Perhaps some mismatch between SceneKit and SpriteKit transitions rendering?

Got this problem on my iPad pro 9.7 as predicted by others above. hshere’s solution worked for me. In fact I trimmed it down to the code below just wrapping the scnView.present code:

#if DEBUG
  scnView.scene = scnScene
#else
  scnView.present(scnScene, with: transition, incomingPointOfView: mainCamera, completionHandler: nil)
#endif