Max Yankov
Max Yankov

Reputation: 13277

UIImagePickerController occasionally freezing up

I use UIImagePickerController in an Unity app. It occasionally freezes when the user presses "done". It happens most often on 3GS — about every third time — but I also had an occasional freeze on iPhone 5. This bug appears on iOS from 4.3 to 7.0. I wasn't able to determine what factors correlate with the freeze. I don't get a memory warning when I get this freeze either.

There are no errors in the log, no crashlog whatsoever. The app continues to run behind UIImagePickerController as normal. There are a lot of messages in the console that seem related, like "deny file-write-data /private/var/mobile/Media/PhotoData", but all of them can occasionally appear both when freeze is present and when everything is working alright.

Here's how I show the picker:

- (void)showPicker:(UIImagePickerControllerSourceType)type
{
    imgPicker = [[[CustomPhotoPicker alloc] init] autorelease];
    imgPicker.delegate = self;
    imgPicker.sourceType = type;
    imgPicker.allowsEditing = _pickerAllowsEditing;

    // wrap and show the modal
    [self showViewControllerModallyInWrapper:imgPicker];

}

And here're the delegate methods:

- (void)imagePickerController:(UIImagePickerController*)imgPicker didFinishPickingMediaWithInfo:(NSDictionary*)info
{
    NSLog( @"imagePickerController didFinishPickingMediaWithInfo");

    // If the freeze is present, this method isn't called
}

- (void)imagePickerController:(UIImagePickerController *)imgPicker
        didFinishPickingImage:(UIImage *)image
                  editingInfo:(NSDictionary *)editingInfo
{
    NSLog( @"imagePickerController didFinishPickingImage");

    // Tried to use deprecated callback. If the freeze is present, this method isn't called either.
}

I would decide that it's a bug inside the UIImagePickerController, but none of iOS developers that don't use Unity ever encountered this problem, and I would suppose that such a bug would already be fixed if it was present in 4.3.

Upvotes: 2

Views: 641

Answers (1)

Zura
Zura

Reputation: 1100

Thre're are a workaround: u can mute CFRunLoopRunInMode in UnityAppController.mm, like this:

- (void)repaintDisplayLink
{
    [_displayLink setPaused: YES];
    {
        static const CFStringRef kTrackingRunLoopMode = CFStringRef(UITrackingRunLoopMode);
        if (![EtceteraManager picking])
        {
            while (CFRunLoopRunInMode(kTrackingRunLoopMode, kInputProcessingTime, TRUE) == kCFRunLoopRunHandledSource)
                ;
        }
    }
}

Upvotes: 1

Related Questions