Posts

Post not yet marked as solved
0 Replies
589 Views
I'm encountering a rather bizarre behavior with a SceneKit application that I am developing. I invoke a method which manipulates the simdWorldPosition property of various SCNNode objects. The method changes the simdWorldPosition in a loop which can execute around ~40k times.I define a DispatchQueue:let updateQueue = DispatchQueue(label: Bundle.main.bundleIdentifier! + ".serialSceneKitQueue")A button press calls the following:@objc func didPressGreedy() { updateQueue.async { let _ = self.Greedy() } }And inside the method:autoreleasepool { for offset in stride(from: 0.0, through: planeWidth, by: increment) { var topLeftTransform = arkitAnchor!.simdWorldTransform * HelperMethods.makeTranslationMatrix(tx: -Float(planeWidth / 2), ty: 0.0, tz: -Float(planeHeight/2)) topLeftTransform = topLeftTransform * HelperMethods.makeTranslationMatrix(tx: Float(offset), ty: 0.0, tz: 0.0) let topEdgePosition = simd_float3(x: topLeftTransform.columns.3.x, y: topLeftTransform.columns.3.y, z: topLeftTransform.columns.3.z) saLabelComponent.simdWorldPosition = topEdgePosition let oldSpriteTransform = sprite.simdWorldTransform for xOffset in stride(from:-0.20, through: 0.20, by: increment) { for yOffset in stride(from: 0.05, through: 0.20, by: increment) { LOOP_1_ITERATIONS += 1 var newSpriteTransform = anchor.simdWorldTransform * HelperMethods.makeTranslationMatrix(tx: Float(xOffset), ty: Float(yOffset), tz: 0.0) sprite.simdWorldTransform = newSpriteTransform } } } }These iterations are slow - I can sometimes see about a thousand manipulations happen in multiple seconds and then it takes a minute to do 50 simdWorldPosition updates. If I tap on the screen I can see the executions speed up.When I use the iOS App Switcher (by just swiping up on the application on iPhone XS and letting it sit in the App Switcher) the application significantly speeds up the execution the iterations by a factor of 10x.Any idea of why this is caused? If I am having conceptual issues please point to relevant topic/articles.
Posted Last updated
.