react-native-image-crop-picker icon indicating copy to clipboard operation
react-native-image-crop-picker copied to clipboard

Fix iPad crash

Open gontovnik opened this issue 3 years ago • 3 comments

gontovnik avatar Mar 21 '22 13:03 gontovnik

nice work @gontovnik confirmed this fixed the crash by popover the actionsheet, thank you

Rachellin77 avatar May 05 '22 01:05 Rachellin77

Tested and works perfectly.

Fixes https://github.com/ivpusic/react-native-image-crop-picker/issues/1765

Steps to reproduce

  1. Select images from library
  2. Only give access to a limited photos set
  3. Click the manage button in iOS photo picker image
  4. App crashes

patch:

patches/react-native-image-crop-picker+0.38.0.patch

diff --git a/node_modules/react-native-image-crop-picker/ios/QBImagePicker/QBImagePicker/QBAlbumsViewController.m b/node_modules/react-native-image-crop-picker/ios/QBImagePicker/QBImagePicker/QBAlbumsViewController.m
index 859d7b8..dec556c 100644
--- a/node_modules/react-native-image-crop-picker/ios/QBImagePicker/QBImagePicker/QBAlbumsViewController.m
+++ b/node_modules/react-native-image-crop-picker/ios/QBImagePicker/QBImagePicker/QBAlbumsViewController.m
@@ -281,6 +281,7 @@ - (void)updateControlState
 -(void)managePermissionAction:(id)sender
 {
     UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:NSLocalizedStringFromTableInBundle(@"permission.title", @"QBImagePicker", self.imagePickerController.assetBundle, nil) message:nil preferredStyle:UIAlertControllerStyleActionSheet];
+    actionSheet.popoverPresentationController.sourceView = sender;
 
     [actionSheet addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTableInBundle(@"permission.cancel", @"QBImagePicker", self.imagePickerController.assetBundle, nil) style:UIAlertActionStyleCancel handler:nil]];

RodolfoGS avatar Jun 30 '22 16:06 RodolfoGS

nice work @gontovnik , I tried the iPad fix, and now is not crashing on the popover action sheet but I was able to reproduce another crash. Steps to reproduce:

  1. select some photos from the gallery so you have permission to select them
  2. kill the app (terminate the app so it is fully closed)
  3. go to the gallery and you will get this kind of popover Screen Shot 2022-09-03 at 12 53 05 AM choose "Keep Current Selection"
  4. click the "Manage" button Screen Shot 2022-09-03 at 12 53 26 AM choose "Select More Photos"
  5. App crashes with error:
Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note:  EXC_CORPSE_NOTIFY
Triggered by Thread:  0

Last Exception Backtrace:
0   CoreFoundation                	    0x7fff204055f4 __exceptionPreprocess + 226
1   libobjc.A.dylib               	    0x7fff201a4a45 objc_exception_throw + 48
2   CoreFoundation                	    0x7fff204145ba +[NSObject(NSObject) instanceMethodSignatureForSelector:] + 0
3   CoreFoundation                	    0x7fff20409bbf ___forwarding___ + 1471
4   CoreFoundation                	    0x7fff2040bd48 _CF_forwarding_prep_0 + 120
5   Bookshelf                     	       0x10059b06d __49-[QBAlbumsViewController managePermissionAction:]_block_invoke + 125 (QBAlbumsViewController.m:291)
6   UIKitCore                     	    0x7fff24432f7f -[UIAlertController _invokeHandlersForAction:] + 105
7   UIKitCore                     	    0x7fff24433868 __103-[UIAlertController _dismissAnimated:triggeringAction:triggeredByPopoverDimmingView:dismissCompletion:]_block_invoke.454 + 16
8   UIKitCore                     	    0x7fff247a421f -[UIPresentationController transitionDidFinish:] + 1269
9   UIKitCore                     	    0x7fff247a8ee4 __56-[UIPresentationController runTransitionForCurrentState]_block_invoke.437 + 199
10  UIKitCore                     	    0x7fff2490579b -[_UIViewControllerTransitionContext completeTransition:] + 101
11  UIKitCore                     	    0x7fff2565d944 __UIVIEW_IS_EXECUTING_ANIMATION_COMPLETION_BLOCK__ + 15
12  UIKitCore                     	    0x7fff2565dc63 -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 797
13  UIKitCore                     	    0x7fff2562df08 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 190
14  UIKitCore                     	    0x7fff2562e523 -[UIViewAnimationState animationDidStop:finished:] + 263
15  UIKitCore                     	    0x7fff2562e6a4 -[UIViewAnimationState animationDidStop:finished:] + 648
16  QuartzCore                    	    0x7fff28a937c6 CA::Layer::run_animation_callbacks(void*) + 318
17  libdispatch.dylib             	    0x7fff20115b25 _dispatch_client_callout + 8
18  libdispatch.dylib             	    0x7fff20123043 _dispatch_main_queue_drain + 1050
19  libdispatch.dylib             	    0x7fff20122c1b _dispatch_main_queue_callback_4CF + 31
20  CoreFoundation                	    0x7fff20371ed5 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
21  CoreFoundation                	    0x7fff2036c6ca __CFRunLoopRun + 2761
22  CoreFoundation                	    0x7fff2036b704 CFRunLoopRunSpecific + 562
23  GraphicsServices              	    0x7fff2cba9c8e GSEventRunModal + 139
24  UIKitCore                     	    0x7fff2509e65a -[UIApplication _run] + 928
25  UIKitCore                     	    0x7fff250a32b5 UIApplicationMain + 101
26  Bookshelf                     	       0x100121108 main + 104 (main.m:7)
27  dyld_sim                      	       0x102f82f21 start_sim + 10
28  dyld                          	       0x109cf951e start + 462

Thanks for your help with the current fix 👍. The crash is reproducible on iPhone and iPad.

damirjuretic avatar Sep 02 '22 23:09 damirjuretic

When this fix will be available in a release? Or should I use this patch for now?

biskis avatar Oct 03 '22 09:10 biskis

@damirjuretic Have you tried since this was merged? https://github.com/ivpusic/react-native-image-crop-picker/pull/1853

It fixed the issue on iPhone but we need this PR for iPad.

markholland avatar Nov 03 '22 09:11 markholland

Hi @markholland , I have tried and it is still crashing so the new version did not fix the Ipad crash or the crash that I have reproduced above.

damirjuretic avatar Nov 12 '22 18:11 damirjuretic

nice work @gontovnik , I tried the iPad fix, and now is not crashing on the popover action sheet but I was able to reproduce another crash. Steps to reproduce:

  1. select some photos from the gallery so you have permission to select them
  2. kill the app (terminate the app so it is fully closed)
  3. go to the gallery and you will get this kind of popover Screen Shot 2022-09-03 at 12 53 05 AM choose "Keep Current Selection"
  4. click the "Manage" button Screen Shot 2022-09-03 at 12 53 26 AM choose "Select More Photos"
  5. App crashes with error:
Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note:  EXC_CORPSE_NOTIFY
Triggered by Thread:  0

Last Exception Backtrace:
0   CoreFoundation                	    0x7fff204055f4 __exceptionPreprocess + 226
1   libobjc.A.dylib               	    0x7fff201a4a45 objc_exception_throw + 48
2   CoreFoundation                	    0x7fff204145ba +[NSObject(NSObject) instanceMethodSignatureForSelector:] + 0
3   CoreFoundation                	    0x7fff20409bbf ___forwarding___ + 1471
4   CoreFoundation                	    0x7fff2040bd48 _CF_forwarding_prep_0 + 120
5   Bookshelf                     	       0x10059b06d __49-[QBAlbumsViewController managePermissionAction:]_block_invoke + 125 (QBAlbumsViewController.m:291)
6   UIKitCore                     	    0x7fff24432f7f -[UIAlertController _invokeHandlersForAction:] + 105
7   UIKitCore                     	    0x7fff24433868 __103-[UIAlertController _dismissAnimated:triggeringAction:triggeredByPopoverDimmingView:dismissCompletion:]_block_invoke.454 + 16
8   UIKitCore                     	    0x7fff247a421f -[UIPresentationController transitionDidFinish:] + 1269
9   UIKitCore                     	    0x7fff247a8ee4 __56-[UIPresentationController runTransitionForCurrentState]_block_invoke.437 + 199
10  UIKitCore                     	    0x7fff2490579b -[_UIViewControllerTransitionContext completeTransition:] + 101
11  UIKitCore                     	    0x7fff2565d944 __UIVIEW_IS_EXECUTING_ANIMATION_COMPLETION_BLOCK__ + 15
12  UIKitCore                     	    0x7fff2565dc63 -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 797
13  UIKitCore                     	    0x7fff2562df08 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 190
14  UIKitCore                     	    0x7fff2562e523 -[UIViewAnimationState animationDidStop:finished:] + 263
15  UIKitCore                     	    0x7fff2562e6a4 -[UIViewAnimationState animationDidStop:finished:] + 648
16  QuartzCore                    	    0x7fff28a937c6 CA::Layer::run_animation_callbacks(void*) + 318
17  libdispatch.dylib             	    0x7fff20115b25 _dispatch_client_callout + 8
18  libdispatch.dylib             	    0x7fff20123043 _dispatch_main_queue_drain + 1050
19  libdispatch.dylib             	    0x7fff20122c1b _dispatch_main_queue_callback_4CF + 31
20  CoreFoundation                	    0x7fff20371ed5 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
21  CoreFoundation                	    0x7fff2036c6ca __CFRunLoopRun + 2761
22  CoreFoundation                	    0x7fff2036b704 CFRunLoopRunSpecific + 562
23  GraphicsServices              	    0x7fff2cba9c8e GSEventRunModal + 139
24  UIKitCore                     	    0x7fff2509e65a -[UIApplication _run] + 928
25  UIKitCore                     	    0x7fff250a32b5 UIApplicationMain + 101
26  Bookshelf                     	       0x100121108 main + 104 (main.m:7)
27  dyld_sim                      	       0x102f82f21 start_sim + 10
28  dyld                          	       0x109cf951e start + 462

Thanks for your help with the current fix 👍. The crash is reproducible on iPhone and iPad.

Line 291 of the QBAlbumsViewController.m refers to the handler function for the alert:

[PHPhotoLibrary sharedPhotoLibrary] presentLimitedLibraryPickerFromViewController:self];

My ObjC isn't that great, but from what i can see, it seems like the managePermission alert is blocking the showing of the shared library🤔? I am unsure about it. But i was unable to reproduce the crash even going through the provided steps🤔

TheRogue76 avatar Dec 02 '22 13:12 TheRogue76

@ivpusic merge this or let someone else manage this repository please.

tomgreco avatar Mar 10 '23 16:03 tomgreco

Tried patching the following changes with iPad Air 5th gen and it still seems to crash

NiharR27 avatar Mar 13 '23 00:03 NiharR27

This fix MUST be merged. This package very commonly causes crashes on iPad for any user that wants to use limited photo permissions. Patching is currently a requirement to use this package. @ivpusic

zholmes1 avatar May 13 '23 12:05 zholmes1

@ivpusic can you kindly publish this fix in a new npm release? Would be great, thanks.

EDIT: Now I'm getting the same (new) crash as @damirjuretic after applying the patch:

I tried the iPad fix, and now is not crashing on the popover action sheet but I was able to reproduce another crash. Steps to reproduce: 
...
click the "Manage" button
choose "Select More Photos"
App crashes with error:

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

Last Exception Backtrace:
0   CoreFoundation                	    0x7fff204055f4 __exceptionPreprocess + 226
1   libobjc.A.dylib               	    0x7fff201a4a45 objc_exception_throw + 48
2   CoreFoundation                	    0x7fff204145ba +[NSObject(NSObject) instanceMethodSignatureForSelector:] + 0
3   CoreFoundation                	    0x7fff20409bbf ___forwarding___ + 1471
4   CoreFoundation                	    0x7fff2040bd48 _CF_forwarding_prep_0 + 120
5   Bookshelf                     	       0x10059b06d __49-[QBAlbumsViewController managePermissionAction:]_block_invoke + 125 (QBAlbumsViewController.m:291)
6   UIKitCore                     	    0x7fff24432f7f -[UIAlertController _invokeHandlersForAction:] + 105
7   UIKitCore                     	    0x7fff24433868 __103-[UIAlertController _dismissAnimated:triggeringAction:triggeredByPopoverDimmingView:dismissCompletion:]_block_invoke.454 + 16
8   UIKitCore                     	    0x7fff247a421f -[UIPresentationController transitionDidFinish:] + 1269
9   UIKitCore                     	    0x7fff247a8ee4 __56-[UIPresentationController runTransitionForCurrentState]_block_invoke.437 + 199
10  UIKitCore                     	    0x7fff2490579b -[_UIViewControllerTransitionContext completeTransition:] + 101
11  UIKitCore                     	    0x7fff2565d944 __UIVIEW_IS_EXECUTING_ANIMATION_COMPLETION_BLOCK__ + 15
12  UIKitCore                     	    0x7fff2565dc63 -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 797
13  UIKitCore                     	    0x7fff2562df08 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 190
14  UIKitCore                     	    0x7fff2562e523 -[UIViewAnimationState animationDidStop:finished:] + 263
15  UIKitCore                     	    0x7fff2562e6a4 -[UIViewAnimationState animationDidStop:finished:] + 648
16  QuartzCore                    	    0x7fff28a937c6 CA::Layer::run_animation_callbacks(void*) + 318
17  libdispatch.dylib             	    0x7fff20115b25 _dispatch_client_callout + 8
18  libdispatch.dylib             	    0x7fff20123043 _dispatch_main_queue_drain + 1050
19  libdispatch.dylib             	    0x7fff20122c1b _dispatch_main_queue_callback_4CF + 31
20  CoreFoundation                	    0x7fff20371ed5 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
21  CoreFoundation                	    0x7fff2036c6ca __CFRunLoopRun + 2761
22  CoreFoundation                	    0x7fff2036b704 CFRunLoopRunSpecific + 562
23  GraphicsServices              	    0x7fff2cba9c8e GSEventRunModal + 139
24  UIKitCore                     	    0x7fff2509e65a -[UIApplication _run] + 928
25  UIKitCore                     	    0x7fff250a32b5 UIApplicationMain + 101
26  Bookshelf                     	       0x100121108 main + 104 (main.m:7)
27  dyld_sim                      	       0x102f82f21 start_sim + 10
28  dyld                          	       0x109cf951e start + 462

EDIT 2:

I was able fix the secondary crash by following this SO answer: https://stackoverflow.com/a/71050608/1516309

It seems you have to add the PhotosUI.framework to your target in Xcode:

image

jforaker avatar May 15 '23 22:05 jforaker