flattenedClone() producing objc_weak_error

Hi,

I am hoping someone can tell me if this is a bug or if I am doing something wrong. Below is a simplified demonstration of the error I am experiencing when attempting to replace a flattened clone with an updated version in my SceneKit app. Each renderer update produces an objc_weak_error to be printed to the console:


objc[1104]: __weak variable at 0x281c48d10 holds 0x28164abc0 instead of 0x28164ac60. This is probably incorrect use of objc_storeWeak() and objc_loadWeak(). Break on objc_weak_error to debug.


If I break on the error, the break occurs on the rendering thread but the stack trace appears almost empty. Below is a simplified UIViewController that causes the error.


import SceneKit


class ViewController: UIViewController, SCNSceneRendererDelegate {


let sceneView = SCNView()

let scene = SCNScene()


var node: SCNNode = {

let sphere = SCNSphere(radius: 1)

sphere.materials.first?.diffuse.contents = UIColor.blue

let node = SCNNode(geometry: sphere)

node.position = SCNVector3(0, 0, -20)

return node

}()


var flattenedNode: SCNNode?


override func viewDidLoad() {

super.viewDidLoad()

sceneView.frame = view.frame

view.addSubview(sceneView)

sceneView.scene = scene

sceneView.delegate = self

sceneView.isPlaying = true

}


func renderer(_ renderer: SCNSceneRenderer, updateAtTime time: TimeInterval) {

flattenedNode?.removeFromParentNode()

flattenedNode = node.flattenedClone()

flattenedNode!.transform = node.transform

scene.rootNode.addChildNode(flattenedNode!)

}

}


Any help appreciated,


Thanks,


Darren.

Replies

I'm having this very same issue. I was trying to figure out what was going on, and this is it. pretty much wasted almost a whole weekend.

I am having the same problem here since Xcode 10. I am dynamically creating compositions of 3d objects and this debug message is nonstop spamming to the console.


EDIT: This problem got fixed with Xcode 11.0.