3

In a Swift iOS app, I have a main SCNNode containing thousands of nodes which all contain the SAME geometry. I am cloning the nodes using .copy():

let firstNode = SCNNode(geometry: myGeo)
for i in 0...10000
{
    let newNode=firstNode.copy()
    rootNode.addChildNode(newNode)
    // Change position
    ...
}
scene.rootNode.addChildNode(rootNode)

All the nodes are properly displayed but performance extremely slow. I am hence using flattenedNode to hope for having an optimized single node using efficiently the fact I am only using 1 geometry:

// Removing of previous "scene.rootNode.addChildNode(rootNode)"
let clo=rootNode.flattenedClone()
scene.rootNode.addChildNode(clo)

However the app crashes with the following error:

-[MTLDebugDevice newBufferWithBytes:length:options:], line 644: error 'Buffer Validation newBufferWith*:length 0x120ba300 must not exceed 256 MB.

As I am only using 1 geometry, is it normal that flattenedNode generates such a huge buffer ?

Laurent Crivello
  • 3,809
  • 6
  • 45
  • 89
  • Adding 10'000 SCNNodes is a really huge numer - it might be too much for SceneKit. What does the app tell you, if you reduce the number of nodes to i.Ex. 500? How big is the geometry object you add? – ZAY Apr 26 '21 at 12:26
  • The object is roughly 3k vertices. But as I can add them separately as individual SCNNodes, but not as single SCNNode, I wonder the use of flattenedNode function... – Laurent Crivello Apr 27 '21 at 15:14
  • in this case I assume the flattenedClone just exeeds the max amound of allowed geometry or whatever. Try splitting it up into several main nodes. I also ran into some issue with flattened clones on very complex geometry. But for common geometry it works quite well. flattenedClones should reduce the total number of draw calls from the renderer on the GPU by merging it's subnodes together (somehow). How exactly they do this, remains the secret of Apple :) – ZAY Apr 27 '21 at 17:06

0 Answers0