Crash in AVCapturePhotoOutput

1.4k Views Asked by At

My app was rejected because of a crash. I was unable to reproduce the crash locally, but thanks to the crash log provided by Apple, I was able to narrow down the offending code to this:

func capturePhoto() {
    let photoOutputSettings = AVCapturePhotoSettings()
    photoOutputSettings.flashMode = Settings.shared.flash
    photoOutputSettings.isAutoStillImageStabilizationEnabled = true
    photoOutputSettings.isHighResolutionPhotoEnabled = true

    self.photoOutput.capturePhoto(with: photoOutputSettings, delegate: self) //crash
}

Also, the reviewer mentioned that they were testing on an iPad running iOS 11.3.1. Here are the relevant parts of the crash log:

{"app_name":"xxxxx","timestamp":"2018-05-07 15:19:10.13 -0700","app_version":"1.0","slice_uuid":"059c64b6-ea13-3bca-97c0-e05dd5eed102","adam_id":1341531999,"build_version":"7","bundleID":"xxxxx","share_with_app_devs":false,"is_first_party":false,"bug_type":"109","os_version":"iPhone OS 11.3.1 (15E302)","incident_id":"4B4E6531-6F8E-4F2A-B262-94685C5FF287","name":"xxxxx"}
Incident Identifier: 4B4E6531-6F8E-4F2A-B262-94685C5FF287
CrashReporter Key:   357841d912f2df927b24861ec18fb870765ae9bd
Hardware Model:      xxx1
Process:             xxxxx [1938]
Path:                /private/var/containers/Bundle/Application/40DDE031-CEDC-4197-989C-C3DEA953492F/xxxxx.app/xxxxx
Identifier:          xxxxx
Version:             7 (1.0)
Code Type:           ARM-64 (Native)
Role:                Foreground
Parent Process:      launchd [1]
Coalition:           xxxxx [1139]


Date/Time:           2018-05-07 15:19:09.9972 -0700
Launch Time:         2018-05-07 15:19:07.3874 -0700
OS Version:          iPhone OS 11.3.1 (15E302)
Baseband Version:    n/a
Report Version:      104

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note:  EXC_CORPSE_NOTIFY
Triggered by Thread:  0

Application Specific Information:
abort() called

Filtered syslog:
None found

Last Exception Backtrace:
0   CoreFoundation                  0x183d42d8c __exceptionPreprocess + 228
1   libobjc.A.dylib                 0x182efc5ec objc_exception_throw + 55
2   AVFoundation                    0x1898cadc4 -[AVCapturePhotoOutput capturePhotoWithSettings:delegate:] + 811
3   QuickRecord                     0x10498e4b0 specialized MainViewController.capturePhotoButtonTapped(_:) + 74928 (MainViewController.swift:210)
4   QuickRecord                     0x10498be34 @objc MainViewController.capturePhotoButtonTapped(_:) + 65076 (MainViewController.swift:187)
5   UIKit                           0x18da726c8 -[UIApplication sendAction:to:from:forEvent:] + 95
6   UIKit                           0x18db938a4 -[UIControl sendAction:to:forEvent:] + 79
7   UIKit                           0x18da7877c -[UIControl _sendActionsForEvents:withEvent:] + 439
8   UIKit                           0x18dbae1dc -[UIControl touchesEnded:withEvent:] + 571
9   QuickRecord                     0x104989c28 specialized TouchAnimationButton.touchesEnded(_:with:) + 56360 (TouchAnimationButton.swift:64)
10  QuickRecord                     0x104988c7c @objc TouchAnimationButton.touchesBegan+ 52348 (_:with:) + 139
11  UIKit                           0x18daf5a48 -[UIWindow _sendTouchesForEvent:] + 2427
12  UIKit                           0x18daea8f8 -[UIWindow sendEvent:] + 3159
13  UIKit                           0x18dae9238 -[UIApplication sendEvent:] + 339
14  UIKit                           0x18e2cac0c __dispatchPreprocessedEventFromEventQueue + 2339
15  UIKit                           0x18e2cd1b8 __handleEventQueueInternal + 4743
16  UIKit                           0x18e2c6258 __handleHIDEventFetcherDrain + 151
17  CoreFoundation                  0x183ceb404 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 23
18  CoreFoundation                  0x183ceac2c __CFRunLoopDoSources0 + 275
19  CoreFoundation                  0x183ce879c __CFRunLoopRun + 1203
20  CoreFoundation                  0x183c08da8 CFRunLoopRunSpecific + 551
21  GraphicsServices                0x185beb020 GSEventRunModal + 99
22  UIKit                           0x18dbe978c UIApplicationMain + 235
23  QuickRecord                     0x104982de0 main + 28128 (PermissionsViewController.swift:14)
24  libdyld.dylib                   0x183699fc0 start + 3


Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libsystem_kernel.dylib          0x00000001837c92ec __pthread_kill + 8
1   libsystem_pthread.dylib         0x000000018396a288 pthread_kill$VARIANT$mp + 376
2   libsystem_c.dylib               0x0000000183737d0c abort + 140
3   libc++abi.dylib                 0x0000000182ed22c8 __cxa_bad_cast + 0
4   libc++abi.dylib                 0x0000000182ed2470 default_unexpected_handler+ 5232 () + 0
5   libobjc.A.dylib                 0x0000000182efc8d4 _objc_terminate+ 35028 () + 124
6   libc++abi.dylib                 0x0000000182eec37c std::__terminate(void (*)+ 111484 ()) + 16
7   libc++abi.dylib                 0x0000000182eebf78 __cxa_rethrow + 144
8   libobjc.A.dylib                 0x0000000182efc7ac objc_exception_rethrow + 44
9   CoreFoundation                  0x0000000183c08e18 CFRunLoopRunSpecific + 664
10  GraphicsServices                0x0000000185beb020 GSEventRunModal + 100
11  UIKit                           0x000000018dbe978c UIApplicationMain + 236
12  QuickRecord                     0x0000000104982de0 main + 28128 (PermissionsViewController.swift:14)
13  libdyld.dylib                   0x0000000183699fc0 start + 4

Any idea what might be causing this crash? Is there something possibly wrong with how the flashMode is handled on the iPad? If so, why does the crash report not mention the flash being an issue like in other SO posts? Any help is appreciated.

1

There are 1 best solutions below

0
On

It's definitely the flash mode. If you are using a camera which has no flash (such as the iPad camera), your app will crash when you call capturePhoto and pass it a parameter other than .off for the flash mode.

To check if a camera has a flash, use the AVCaptureDevice.hasFlash property on that camera.