Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIImagePickerControllerOriginalImage nil causing crash on photo capture

Tags:

ios

I am getting a crash in several versions of my apps, and it seems to have started happening on iOS8. I only experience it through crash reports and can't reproduce it on my test devices. It seems to be when a user captures an image (or selects it from the library?) and the original image cannot be set because the image is nil. The closest issue I can find while searching is this:

https://github.com/B-Sides/ELCImagePickerController/issues/58

Another possibility is when it is backgrounded with a specific race condition timing, which I'm also unable to reproduce.

http://openradar.appspot.com/19953748

but I don't think my error is coming from a stream image being selected. I'm hoping to see if anyone else is getting this error, and has either figured out a solution to consistently catch the exception, or detect when this happens, or disable a specific user action (like backgrounding the app while uploading photos) to avoid a crash.

Fatal Exception: NSInvalidArgumentException *** setObjectForKey: object cannot be nil (key: UIImagePickerControllerOriginalImage)

Thread : Fatal Exception: NSInvalidArgumentException
0  CoreFoundation                 0x2b381fef __exceptionPreprocess + 126
1  libobjc.A.dylib                0x39633c8b objc_exception_throw + 38
2  CoreFoundation                 0x2b29daa3 -[__NSDictionaryM setObject:forKey:] + 850
3  PhotoLibrary                   0x345bf8f3 __CreateInfoForImage
4  PhotoLibrary                   0x345bf1ad PLNotifyImagePickerOfImageAvailability
5  PhotoLibrary                   0x345d384b -[PLUICameraViewController cameraView:photoSaved:]
6  PhotoLibrary                   0x34606a73 -[PLImagePickerCameraView cropOverlay:didFinishSaving:]
7  PhotoLibrary                   0x3460706d -[PLImagePickerCameraView captureController:didCompleteResponse:forStillImageRequest:error:]
8  CameraKit                      0x303392a5 -[CAMCaptureController _completedResponse:forRequest:error:]
9  CameraKit                      0x30338bfb __56-[CAMCaptureController enqueueStillImageCaptureRequest:]_block_invoke_32160
10 libdispatch.dylib              0x39b9e2e3 _dispatch_call_block_and_release + 10
11 libdispatch.dylib              0x39b9e2cf _dispatch_client_callout + 22
12 libdispatch.dylib              0x39ba1d2f _dispatch_main_queue_callback_4CF + 1330
13 CoreFoundation                 0x2b347609 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
14 CoreFoundation                 0x2b345d09 __CFRunLoopRun + 1512
15 CoreFoundation                 0x2b292201 CFRunLoopRunSpecific + 476
16 CoreFoundation                 0x2b292013 CFRunLoopRunInMode + 106
17 GraphicsServices               0x32b71201 GSEventRunModal + 136
18 UIKit                          0x2ea36a59 UIApplicationMain + 1440
19 Pact                           0x000b26ab main (main.m:17)
20 libdyld.dylib                  0x39bbfaaf start + 2

EDIT Sept 18, 2017 I have not revisited this issue and have not found a solution, unfortunately :(

like image 978
mitrenegade Avatar asked Apr 24 '15 00:04

mitrenegade


1 Answers

I was able to reproduce this crash from exactly the scenario based in http://openradar.appspot.com/19953748 . I set up an infinite loop that took a picture every 2 seconds and I continuously moved the app between background and foreground. It crashes with the same stack trace pretty quickly. Though I am not sure of the root cause for this I am able to resolve it by simply checking for application state before taking the picture

//Swift
if UIApplication.sharedApplication().applicationState == .Active {
                // Take picture
} 
like image 124
Kedar Avatar answered Nov 19 '22 04:11

Kedar