Search code examples
iossprite-kitscenekitmetaliphone-x

Pixel Format Error with SceneKit + SpriteKit Overlay on iPhone X


I have a nasty problem with a SceneKit app when running on iPhone X (iOS 11.1.2) with the Metal renderer. The app has the plist key SCNDisableLinearSpaceRendering set to YES in order to get the same color rendering on iOS 9 and later versions. It also has a SpriteKit 2D overlay added via overlaySKScene.

In release builds, the iPhone X shows weird colors in the overlay, but not in the 3D scene. Debug builds crash with the error log:

-[MTLDebugRenderCommandEncoder validateFramebufferWithRenderPipelineState:]:1196: failed assertion `For color attachment 0, the render pipeline's pixelFormat (MTLPixelFormatRGBA8Unorm_sRGB) does not match the framebuffer's pixelFormat (MTLPixelFormatBGR10_XR).'

The way I understand this is that the pixel format of the 2D and 3D scenes are different. I have no idea how I could change that. Any suggestions?

The error will only show on the iPhone X, not the simulator or any other device I have tested (4s, 5s, 6 Plus, 6s, 7, iPad Pro 1G). When I use the OpenGL ES renderer, everything is fine. When I switch off SCNDisableLinearSpaceRendering, everything works with the Metal renderer too, but the 3D color rendering is very different, of course.

If you have an iPhone X you can reproduce this by creating a new project from the Game template and adding this code in viewDidLoad():

let overlaySize = CGSize(width: 100, height: 100)
let overlay = SKScene(size: overlaySize)
let sprite = SKSpriteNode(color: UIColor.blue, size: overlaySize)
overlay.addChild(sprite)
scnView.overlaySKScene = overlay

I'd also be very interested to hear if this also occurs on iPhone 8/8 Plus?


Solution

  • In the meantime I saw people reporting several other SceneKit issues with iOS 11. So I believe this is a bug in iOS 11. I filed a radar a month ago but the problem still exists in 11.2.5.

    My current workaround ist to use the OpenGL ES renderer instead of Metal.