Skip to content

[image_picker][iOS] Occasional crash, maybe due to multiple modal viewControllers being presented #108900

@ChristianEdwardPadilla

Description

@ChristianEdwardPadilla

Occasionally (hundreds of crashes per month from userbase of millions) seeing the following error message:

Application tried to present modally a view controller <PHPickerViewController: 0x157b805f0> that is already being presented by <FlutterViewController: 0x111824c00>.

Stacktrace:

Stack Trace:
0x0000000180c7d0fc ( CoreFoundation + 0x000990fc ) __exceptionPreprocess
0x00000001994cdd60 ( libobjc.A.dylib + 0x00015d60 ) objc_exception_throw
0x0000000183561984 ( UIKitCore + 0x004d4984 ) -[UIViewController _presentViewController:withAnimationController:completion:]
0x000000018334c3f4 ( UIKitCore + 0x002bf3f4 ) __63-[UIViewController _presentViewController:animated:completion:]_block_invoke
0x00000001832fca34 ( UIKitCore + 0x0026fa34 ) -[_UIViewControllerTransitionCoordinator _applyBlocks:releaseBlocks:]
0x000000018353209c ( UIKitCore + 0x004a509c ) -[_UIViewControllerTransitionContext _runAlongsideCompletions]
0x00000001832cdf24 ( UIKitCore + 0x00240f24 ) -[_UIViewControllerTransitionContext completeTransition:]
0x00000001834e0994 ( UIKitCore + 0x00453994 ) -[UITransitionView notifyDidCompleteTransition:]
0x000000018333718c ( UIKitCore + 0x002aa18c ) -[UITransitionView _didCompleteTransition:]
0x0000000183351dcc ( UIKitCore + 0x002c4dcc ) -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:]
0x000000018321d2e4 ( UIKitCore + 0x001902e4 ) -[UIViewAnimationState sendDelegateAnimationDidStop:finished:]
0x0000000183231a58 ( UIKitCore + 0x001a4a58 ) -[UIViewAnimationState animationDidStop:finished:]
0x0000000183231bc0 ( UIKitCore + 0x001a4bc0 ) -[UIViewAnimationState animationDidStop:finished:]
0x0000000184a06a04 ( QuartzCore + 0x000c8a04 ) CA::Layer::run_animation_callbacks(void*)
0x00000001808ef66c ( libdispatch.dylib + 0x0000466c ) _dispatch_client_callout
0x00000001808fdb6c ( libdispatch.dylib + 0x00012b6c ) _dispatch_main_queue_callback_4CF
0x0000000180c35d80 ( CoreFoundation + 0x00051d80 ) __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
0x0000000180beff58 ( CoreFoundation + 0x0000bf58 ) __CFRunLoopRun
0x0000000180c03464 ( CoreFoundation + 0x0001f464 ) CFRunLoopRunSpecific
0x000000019c7a7388 ( GraphicsServices + 0x00001388 ) GSEventRunModal
0x00000001835a65cc ( UIKitCore + 0x005195cc ) -[UIApplication _run]
0x0000000183324f70 ( UIKitCore + 0x00297f70 ) UIApplicationMain
0x00000001023ccbf0 ( ios_prod_global - ./nbu/paisa/gpay/ios/main.m:73 ) main
0x0000000108e25aa0 (  + 0x108e25aa0 )

We know image_picker is the culprit because it is the only use of PHPickerViewController in this app.

Steps to Reproduce

Unknown exactly what causes this crash or how to reproduce.

Expected results: image_picker works as expected
Actual results: occasional crashes

Suggested fix:

Based on https://stackoverflow.com/questions/7429014/application-tried-to-present-modally-an-active-controller, we might want to have !viewController.presentingViewController be true before calling [[self viewControllerWithWindow:nil] presentViewController:pickerViewController]; here (and maybe elsewhere in the file): https://github.com/flutter/plugins/blob/main/packages/image_picker/image_picker_ios/ios/Classes/FLTImagePickerPlugin.m#L426

Metadata

Metadata

Labels

P1High-priority issues at the top of the work listc: crashStack traces logged to the consoleneeds repro infoAutomated crash report whose cause isn't yet knownp: image_pickerThe Image Picker plugin.packageflutter/packages repository. See also p: labels.platform-iosiOS applications specificallyr: fixedIssue is closed as already fixed in a newer versionteam-iosOwned by iOS platform teamtriaged-iosTriaged by iOS platform team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions