I have an ARSCNView
in the ViewController.swift
and I want to save the ARFrames
to a pre-allocated array in
func session(_ session: ARSession, didUpdate frame: ARFrame)
However, after processing about 11-13 ARFrames
the whole ARSCNView
will freeze by using
self.ARFrames.append(frame)
What makes it strange is that func session(_ session: ARSession, didFailWithError error: Error)
is not calling during the process, nor any other errors were reported, the app doesn't crash and every other user control works fine, only ARSCNView
freeze and didpUdate event won't be called. Similar to ARSCNView freezes when adding 14 ARAnchor subclass objects with strong reference but the pages there doesn't have a solution. Also after app goes to the background and returns back, sessionWasInterrupted(:)
and sessionInterruptionEnded(:)
being called, even though scene view was freezed before. Is this a bug of iOS 11?
Here's the full code I am using in my app.
import UIKit
class ViewController: UIViewController,ARSCNViewDelegate,ARSessionDelegate {
@IBOutlet var sceneView: ARSCNView!
let configuration = ARFaceTrackingConfiguration()
var ARFrames = [ARFrame]()
var imgCount = 0
override func viewDidLoad() {
super.viewDidLoad()
ARFrames.reserveCapacity(300)
sceneView.delegate = self
sceneView.session.delegate = self
sceneView.session.run(configuration, options: [.resetTracking, .removeExistingAnchors])
}
func session(_ session: ARSession, didUpdate frame: ARFrame) {
if (frame.capturedDepthData == nil || self.imgCount >= 300){
return
}
DispatchQueue.global().async {
self.ARFrames.append(frame)
self.imgCount += 1
}
}
}