SceneView with .frame() turns black

Hello,

I experienced a strange behavior with SceneView and a .frame() modifier. Here is a minimal example:

import SwiftUI
import SceneKit

struct MinimalSceneKitExample: View {
    var simpleScene: SCNScene {
        let scene = SCNScene()
        
        let boxGeometry = SCNBox(width: 0.1, height: 0.1, length: 0.1, chamferRadius: 0)
        let boxNode = SCNNode(geometry: boxGeometry)
        boxNode.position = SCNVector3(0, 0, 0)
        
        scene.rootNode.addChildNode(boxNode)
        return scene
    }
    
    var body: some View {
        SceneView(
            scene: SCNScene(),
            options: [.allowsCameraControl, .autoenablesDefaultLighting]
        )
        .frame(maxWidth: .infinity, maxHeight: 312.6)
    }
}

This code turns the SceneView into a black view. Only some height values are causing this behavior. For example the height value 312.3 is fine. In my app, I'm using a dynamic height value that depends on the device's screen size which results in this behavior on some devices. Took me days to find this cause. So far integer values seem to always work which is what I will use as a quick fix for now.

Should I file a bug ticket for this?

Answered by DTS Engineer in 820264022

Hello @Heideltraut,

Please file a bug report for this issue using Feedback Assistant.

-- Greg

There is a small mistake in my source code and I can't edit it. It should be like this instead:

var body: some View {
        SceneView(
            scene: simpleScene,
            options: [.allowsCameraControl, .autoenablesDefaultLighting]
        )
        .frame(maxWidth: .infinity, maxHeight: 312.6)
    }

Hello @Heideltraut,

Please file a bug report for this issue using Feedback Assistant.

-- Greg

SceneView with .frame() turns black
 
 
Q