imaginary-cloud / CameraManager

Simple Swift class to provide all the configurations you need to create custom camera view in your app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

_getMovieOutput() causing crash when orientation is changed specifically on iPhone6 and iPhone 6s

kselvin opened this issue · comments

The error only occurs on iPhone6 and 6s and happens kind of randomly, after an initial crash for a user it will most likely not happen again.

see thread below

Fatal Exception: NSInvalidArgumentException
*** -[AVCaptureSession addOutput:] An AVCaptureOutput instance may not be added to more than one session

0 CoreFoundation 0x1c8088ec4 __exceptionPreprocess
1 libobjc.A.dylib 0x1c7259a40 objc_exception_throw
2 AVFoundation 0x1ce18151c -[AVCaptureSession addOutput:]
3 CameraManager 0x1015a9ad4 specialized CameraManager._getMovieOutput() (CameraManager.swift:1162)
4 CameraManager 0x1015a1dd4 CameraManager._orientationChanged() (CameraManager.swift:1193)
5 CameraManager 0x1015b0f20 partial apply for closure 1 in CameraManager._startFollowingDeviceOrientation() ()

it seems that maybe the repeated calls of _getMovieOutput when orientation changes could be causing it?

Please let me know if you have a way to reproduce it. Thanks.

The best way to reproduce is to reinstall the app go to your camera view, turn to horizontal and start recording -- still I am unable to reproduce every time.

I've actually now seen the crash on more than just the iPhone 6/6s but it definitely happens more frequently the older the device.

a great way to replicate this is

  1. run app from xcode
  2. open camera in app
  3. press play on xcode again and repeat steps 1 and 2
    do this a few times and then press record

Terminating app due to uncaught exception 'NSGenericException', reason: '*** -[AVCaptureSession startRunning] startRunning may not be called between calls to beginConfiguration and commitConfiguration’

just a shot in the dark here but maybe committing configuration takes too long (which would explain why this problem is more likely to occur on the older devices)

could we fix it synchronously calling this block?
DispatchQueue.main.sync {
captureSession.beginConfiguration()
captureSession.addOutput(movieOutput!)
captureSession.commitConfiguration()
}

Any update on this? +1

Should be fixed in the latest version. If the issue persists, please feel free to open a new issue.