ARVideoKit icon indicating copy to clipboard operation
ARVideoKit copied to clipboard

SceneKit Audio Causes Immediate Crash on Record

Open gheatley opened this issue 6 years ago • 11 comments

callstack workspace

iPhone X iOS 11.3 ARSCNView Any ideas?

gheatley avatar Apr 28 '18 22:04 gheatley

@gheatley, can you share how you're configuring RecordAR object in your project?

AFathi avatar Apr 28 '18 22:04 AFathi

pretty much as mandated:

func viewDidLoad() {
//ARVideoKit
        arVideoKitRecorder = RecordAR(ARSceneKit: ARView)
        
        // Set the recorder's delegate
        arVideoKitRecorder?.delegate = self
        
        // Set the renderer's delegate
        arVideoKitRecorder?.renderAR = self
        
        // Configure the renderer to perform additional image & video processing 👁
        arVideoKitRecorder?.onlyRenderWhileRecording = true
        
        // Configure ARKit content mode. Default is .auto
        arVideoKitRecorder?.contentMode = .aspectFill
        
        //record or photo add environment light rendering, Default is false
        arVideoKitRecorder?.enableAdjsutEnvironmentLighting = false
        
        // Set the UIViewController orientations
        arVideoKitRecorder?.inputViewOrientations = [.landscapeLeft, .landscapeRight, .portrait]
        // Configure RecordAR to store media files in local app directory
        arVideoKitRecorder?.deleteCacheWhenExported = true
}

This startSession is NOT called from viewWillAppear()

func startSession() {
        
        guard ARWorldTrackingConfiguration.isSupported else { showUnsupportedDeviceError(); return }
        
        configuration.detectionImages = referenceImages
        configuration.planeDetection = planeDetectionConfig
        
        arVideoKitRecorder?.prepare(configuration)
        ARView.session.run(configuration)
        sessionIsPaused = false
        
    }

Recording triggered like so:

func presentCamera() {

        var result = "DEFAULT"
        
        switch arVideoKitRecorder!.status {
        case RecordARStatus.unknown:
            result = "unknown"
            break
        case RecordARStatus.readyToRecord:
            result = "readyToRecord"
            break
        case RecordARStatus.recording:
            result = "recording"
            break
        case RecordARStatus.paused:
            result = "paused"
            break
        }
        
        #if DEBUG
        log(self, message: "arVideoKitRecorder?.status:\(result)")
        #endif
        
        //Record
        if arVideoKitRecorder?.status == .readyToRecord {
            #if DEBUG
            log(self, message: "Go")
            #endif
            recordingQueue.async { self.arVideoKitRecorder?.record() }
        } else if arVideoKitRecorder?.status == .recording {
            arVideoKitRecorder?.stop() { path in
                self.arVideoKitRecorder?.export(video: path) { saved, status in
                    //DispatchQueue.main.sync {
                      //  self.exportMessage(success: saved, status: status)
                    //}
                }
            }
        }

I have tinkered-around with the settings to try different things to no avail. I DID manage to get it to record once successfully though. (Beautiful results btw). Have tried starting the record both with & without being on those queues.

gheatley avatar Apr 28 '18 23:04 gheatley

Looks like it's mentioning audio there at the top of the stack. Maybe if Mic recording is disabled? I am using 3D positional audio in the scene.. if that would affect things in any way..

gheatley avatar Apr 28 '18 23:04 gheatley

NB: After further playing, GIFs crash too exactly the same. However, Photos & LivePhotos work fine.

gheatley avatar Apr 28 '18 23:04 gheatley

Ok. I've found what's causing it: Audio played on SceneKit Nodes. I can't be sure if it's strictly nodes employing positional audio or just any nodes playing audio at all in the SCNScene (as I'm using both). But as soon as i detatch my SCNNodes which have audio playing & then run & record, it works! Any way to fix this?

gheatley avatar Apr 29 '18 11:04 gheatley

@gheatley, try this:

recorder?.enableMixWithOthers = false

AFathi avatar Apr 29 '18 18:04 AFathi

That reduces the crash rate to about just 50% of the time. However there is no audio at all (nor the mic audio) in the finished recordings.

gheatley avatar Apr 29 '18 19:04 gheatley

@gheatley, I'll try to reproduce this bug and get back to you soon.

AFathi avatar May 01 '18 16:05 AFathi

@AFathi Any luck?

gheatley avatar May 06 '18 08:05 gheatley

not sure , but try this

screenRecorder?.requestMicPermission = .manual

my crash got fixed by this.

devajith avatar May 28 '18 07:05 devajith

Thanks for the suggestion @devajith . Have tried it & sadly this doesn't fix the problem.

gheatley avatar May 29 '18 12:05 gheatley