ARVideoKit icon indicating copy to clipboard operation
ARVideoKit copied to clipboard

LivePhoto = nil CRASH

Open gheatley opened this issue 5 years ago • 2 comments

screen shot 2018-07-22 at 10 55 05 screen shot 2018-07-22 at 10 55 47

I am using iOS12 beta 4 with XCode 10 yes, but the same problem was happening with iOS 11.4

This occurs regularly when actioning a livePhoto:

if arVideoKitRecorder!.status == .readyToRecord {
    audioManager.play(.CameraShutter)
    livePhotoState = .takingLivePhoto
    livePhotoCaptureTimer = Timer.scheduledTimer(timeInterval: livePhotoDuration, target: self, selector: (#selector(finishedTakingLivePhoto)), userInfo: nil, repeats: false)
    caprturingQueue.async { [weak self] in
        self?.arVideoKitRecorder?.livePhoto(export: true) { [weak self] ready, photo, status, saved in
                        
            #if DEBUG
            log(self!, message: "LivePhoto process concluded. ready:\(ready) status:\(status.rawValue) saved:\(saved)")
            #endif
                        
            self?.livePhotoCaptureTimer.invalidate()
            self?.livePhotoState = .ready
                        
            //if ready {
                //Do something with the `photo` (PHLivePhotoPlus)
            //}
                        
            //if saved { //saved flag is not reliable
                self?.overlay?.inform(.livePhotoSaved)
            //} else {
                //self?.overlay?.inform(.livePhotoFailed)
            //}
        }
    }
}

Settings:

    arVideoKitRecorder?.onlyRenderWhileRecording = true
    arVideoKitRecorder?.contentMode = .aspectFill
    arVideoKitRecorder?.enableAdjustEnvironmentLighting = true
    arVideoKitRecorder?.inputViewOrientations = [.landscapeLeft, .landscapeRight, .portrait]
    arVideoKitRecorder?.deleteCacheWhenExported = true

gheatley avatar Jul 22 '18 10:07 gheatley

@gheatley I can see from your screenshot "Generate+LivePhoto.swift: line 58", the attempt to unwrap photo has already failed in this case. So I think your issue should be unwrapping a nil value.

pingchen114 avatar Jul 29 '18 04:07 pingchen114

Sometimes the LivePhoto works ok, sometimes it doesn't. The problem is originating here in Generate+LivePhoto:

PHLivePhoto.request(withResourceFileURLs: [keyLiveFrames, keyLiveFrame], placeholderImage: UIImage(cgImage: cgImg), targetSize: .zero, contentMode: .aspectFit) { photo, settings in
    logAR.remove(from: keyFrame)
    logAR.remove(from: liveFrames)
    if let livePhoto = photo {
        let finalPhoto = PHLivePhotoPlus(photo: livePhoto)
        finalPhoto.keyPhotoPath = keyLiveFrame
        finalPhoto.pairedVideoPath = keyLiveFrames
        finished?(true, finalPhoto, finalPhoto.pairedVideoPath, finalPhoto.keyPhotoPath)
        return
    }else{
        let finalPhoto = PHLivePhotoPlus(photo: photo!) //CRASH photo = nil HERE
        finalPhoto.keyPhotoPath = keyLiveFrame
        finalPhoto.pairedVideoPath = keyLiveFrames
        finished?(false, finalPhoto, finalPhoto.pairedVideoPath, finalPhoto.keyPhotoPath)
        return
    }
}

This is occurring regularly now. I get two errors when things go wrong: Error: Invalid image metadata Error: Invalid video metadata

iOS12 Swift 4.2 XCode10 on iPhoneX device Really could do with sorting this one

gheatley avatar Oct 04 '18 16:10 gheatley