dimonovdd / Xamarin.MediaGallery

This plugin is designed to picking and save images and video files from native gallery of Android and iOS devices and capture photos
MIT License
148 stars 18 forks source link

App Crashes when I take 150+ photos using CapturePhotoAsync() in IOS platform . #89

Closed thanigaiharan closed 2 years ago

thanigaiharan commented 2 years ago

Description

we are using this nuget in Xamarin.ios application. Our application is a Fleet management application where we used to do inspection for multiple vehicle tires . While doing inspection we take multiple photos for tires (around 200 photos for one vehicle). While doing so the app crashes in "await MediaGallery.CapturePhotoAsync()". we are unable to handle this exception and even the crash log is not reported in Testflight. Due to this crash we are losing the inspection data and user need to do inspection again. Appreciate the help to fix this issue soon.

Actual Behavior

App Should not crash.

Expected behavior

App crashes in iPad Pro (120 photos) , Iphone XR (around 300 photos), iPhone 11 Pro (400 photos)

Code snippet


try
{
    var photo = await MediaGallery.CapturePhotoAsync();

    string photoPath = await SavePhotoLocallyAsync(photo, directory);

    var options = new CompressImageOptions
    {
        CompressionQuality = this.GetCompressionQuality(photoResolution)
    };

    //Android throws a "java.lang.RuntimeException: Canvas: trying to draw too large bitmap" exception when taking pictures on 64MP phones.
    //Added a MaxWidthHeight constraint to control max resolution.
    if (ApplicationHelper.SelectedPlatform == ApplicationHelper.ApplicationPlatform.Android)
    {
        const int SIXTEEN_MEGAPIXEL_WIDTH = 4920;
        options.PhotoSize = PhotoSize.MaxWidthHeight;
        options.MaxWidthHeight = SIXTEEN_MEGAPIXEL_WIDTH;
    }

    await this.compressImageService.ResizeAndCompressImage(photoPath, options);

    photo.Dispose();

    return photoPath;
}
catch(Exception ex)
{
    throw ex;
}

Steps to reproduce the behavior

Screenshots or Videos

Reproduction Link

Configuration

dimonovdd commented 2 years ago

@thanigaiharan Hi. It seems to me that you are facing memory leaks. Have you tried using Xamarin Profiler or subscribing to ReceiveMemoryWarning? 200 photos is quite a lot. On which line does the app crash?

thanigaiharan commented 2 years ago

@dimonovdd Thanks for your quick reply. The app crashes in "var photo = await MediaGallery.CapturePhotoAsync();". If this method call throws exception if there is a memory leak then we can catch and avoid the app crash.

thanigaiharan commented 2 years ago

@dimonovdd when we call "await MediaGallery.CapturePhotoAsync()" method it shows the image

The app crashes exactly when I click on the Shutter button to take photo. Appreciate your help on this.

dimonovdd commented 2 years ago

I do not know how to help, I will not be able to test it. I have iPhone 12 mini and 13 Pro. I will have to take more than 400 photos every time. Could you provide more information? For example, you can collect logs from an iPhone using Console app on Mac

thanigaiharan commented 2 years ago

@dimonovdd I am getting this error in console log when ever I click on the Shutter button after I call "await MediaGallery.CapturePhotoAsync()".

error 01:57:52.245770+0800 AppName findWriterForTypeAndAlternateType:119: unsupported file format 'public.heic'

image

Does this help?

thanigaiharan commented 2 years ago

@dimonovdd When I checked with the Xcode Profiler. Below is the screen shots

  1. Initial stage

image

  1. Just before the crash

image

dimonovdd commented 2 years ago

@thanigaiharan Can you email me the full logs from native logs from Xcode or Console?

dimonovdd commented 2 years ago

1) Have you used Essentials? is there such this issue? 2) Did you also get this crash in debug or in release builds?

dimonovdd commented 2 years ago

@thanigaiharan You can find the device logs in Xcode -> Window -> Devices and Simulators -> View Device Logs I hope that today or tomorrow you will send more information. I would like to try to help you with it tomorrow.

thanigaiharan commented 2 years ago

@dimonovdd sent email with the crash logs and details.

dimonovdd commented 2 years ago

200 images is pretty high for normal usage. I thihk that you should report this issue to Apple. You can specify that UIImagePickerController is used to capture photos.

If you write to apple, please let us know about the progress of solving the problem here

thanigaiharan commented 2 years ago

@dimonovdd When we capture the photo and show the preview with 'Use photo' and 'Retake' option (as shown in below screenshot), are we using the UIImageViewer . If so are you setting the new Image(filename) or UIImage.FromFile(filepath)?

image

dimonovdd commented 2 years ago

When we capture the photo and show the preview with 'Use photo' and 'Retake' option (as shown in below screenshot), are we using the UIImageViewer

No this is the native behavior of UIImagePickerController. All the project sources are in this repository. You can watch it.

1) PlatformCapturePhotoAsync

2) PhotoFile

dimonovdd commented 2 years ago

I'm wondering if there are any updates on this?