What can I do about `MTLTextureDescriptor has invalid pixelFormat (0)?

Upon initialization of my scene, on rare occasions the app will crash with this error

com.apple.scenekit.scnview-renderer (18): signal SIGABRT

The following is printed in the console

-[MTLTextureDescriptorInternal validateWithDevice:]:1097: failed assertion `MTLTextureDescriptor has invalid pixelFormat (0).'

Lastly, here is the function which is called before the crash

func setupRandomScene() {

self.scene.rootNode.childNodes.forEach({ (node) in

node.removeFromParentNode()

})

DispatchQueue.main.async {

if !Model.shared.hasSeenTooltips {

self.scene = SCNScene(named: "art.scnassets/levels/level\(0).scn")!

} else {

let randomInt = Int.random(in: 1...8)

self.scene = SCNScene(named: "art.scnassets/levels/level\(randomInt).scn")!


}

let randomColorInt = Int.random(in: 1...4)

switch randomColorInt {

case 1:

self.scene.background.contents = UIImage(named: "art.scnassets/bg/purple")

case 2:

self.scene.background.contents = UIImage(named: "art.scnassets/bg/pink")

case 3:

self.scene.background.contents = UIImage(named: "art.scnassets/bg/orange")

case 4:

self.scene.background.contents = UIImage(named: "art.scnassets/bg/teal")

case 5:

self.scene.background.contents = UIImage(named: "art.scnassets/bg/cyan")

default:

self.scene.background.contents = UIImage(named: "art.scnassets/bg/blue")

}

self.scene.rootNode.addChildNode(self.cameraNode)

self.scene.physicsWorld.contactDelegate = self

self.scene.physicsWorld.gravity = SCNVector3(0, -9.8, 0)

self.playerNode = SCNNode()

self.setupPlayerNode()

self.setupSounds()

self.dancingAnimation = SCNAnimation(named: "art.scnassets/stickman/dance\(Int.random(in: 1...10)).scnanim")

let directionalLight = SCNNode()

directionalLight.name = "directional"

directionalLight.position = SCNVector3(-10, 50, -100)

directionalLight.light = SCNLight()

directionalLight.light?.type = .directional

directionalLight.light?.castsShadow = true

directionalLight.light?.shadowRadius = 2 // 1000

directionalLight.light?.shadowSampleCount = 20 // 20

directionalLight.light?.shadowMapSize = CGSize(width: 2000, height: 2000)

directionalLight.light?.intensity = 2000

directionalLight.eulerAngles = SCNVector3(0, -toRadians(angle: 150), -toRadians(angle: 60))

self.scene.rootNode.addChildNode(directionalLight)

let ambientLight = SCNNode()

ambientLight.name = "ambient"

ambientLight.light = SCNLight()

ambientLight.light?.castsShadow = false

ambientLight.light?.type = .ambient

ambientLight.light?.color = UIColor.darkGray

ambientLight.light?.intensity = 5000

self.scene.rootNode.addChildNode(ambientLight)

self.cameraNode.position = SCNVector3(self.playerNode.position.x, self.playerNode.position.y + 5, self.playerNode.position.z - 9)

self.cameraNode.eulerAngles = SCNVector3(-toRadians(angle: 5), -toRadians(angle: 180), 0)

self.cameraNode.camera = SCNCamera()

self.gameState = .menu

self.scnView = nil

self.scnView = self.view as? SCNView

if let _ = self.scnView {

self.scnView!.delegate = self

self.overlayScene = OverlayScene(with: self.overlaySceneSize, isLive: self.broadcastController.isBroadcasting)

self.scnView!.overlaySKScene = self.overlayScene

self.scnView!.present(self.scene, with: .fade(with: .white, duration: 1), incomingPointOfView: nil, completionHandler: nil)

}

if !Model.shared.soundIsMuted {

self.playerNode.runAction(self.playWooshSound)

}

self.positiveHaptic.prepare()

}

}

Replies

On which device or simulator do you run ?


What is the format of your images (png ? other ?)

May have a look at this discussion:

h ttps://forum.unity.com/threads/metal-error-on-4-6-3-solved.300984/

Hello Claude,


I came accross this post before making mine although it did not solve my issue. Setting the default rendering api to OPEN GL completely disfigures my app. (Multiple lights seem to be ignored and shadows are go away with OPEN GL)

As for the images, all of my images are in png format.


Thanks for taking the time to help me out