capacitor-plugins icon indicating copy to clipboard operation
capacitor-plugins copied to clipboard

Camera.getPhoto() randomly crashes the application on iOS and Android

Open corentincouq opened this issue 2 years ago • 3 comments

Bug Report

Plugin(s)

"@capacitor/camera": "5.0.7"

Capacitor Version

💊   Capacitor Doctor  💊 

Latest Dependencies:

  @capacitor/cli: 5.5.1
  @capacitor/core: 5.5.1
  @capacitor/android: 5.5.1
  @capacitor/ios: 5.5.1

Installed Dependencies:

  @capacitor/android: 5.5.1
  @capacitor/ios: 5.5.1
  @capacitor/cli: 5.5.1
  @capacitor/core: 5.5.1

[success] iOS looking great! 👌
[success] Android looking great! 👌

Platform(s)

iOS 17 Android 13 And probably other versions

Current Behavior

When I use the getPhoto() function, my application crashes randomly.

The crash occurs randomly on the same photo, whether in the gallery or with the camera.

This causes the application to crash or nothing works any more, as if we were in an infinite loop.

It is impossible to catch an error or stop the process without killing the application.

Expected Behavior

I'd like to be able to retrieve the response from getPhoto() or at least prevent the process from crashing, making my application unusable.

Code Reproduction

I have two functions used in this process :

export async function recuperePhoto(sourcePhoto: 'camera' | 'photos') {
  const source = sourcePhoto === 'camera' ? CameraSource.Camera : CameraSource.Photos;
  const photoRecuperer: Photo = await Camera.getPhoto({
    resultType: CameraResultType.Base64,
    source,
    quality: 50,
  });

  const photoEnregistrer = await enregistreImage(photoRecuperer);
  return photoEnregistrer.data;
}

async function enregistreImage(fichier: Photo) {
  if (fichier.base64String != null) {
    const base64Data = `data:image/${fichier.format};base64,${fichier.base64String}`;
    return { data: base64Data };
  }
  return { data: undefined };
}

If I try to modify the code to catch an error like this :

export async function recuperePhoto(sourcePhoto: 'camera' | 'photos') {
  const source = sourcePhoto === 'camera' ? CameraSource.Camera : CameraSource.Photos;

  try {
    const photoRecuperer: Photo = await Camera.getPhoto({
      resultType: CameraResultType.Base64,
      source,
      quality: 50,
    });
  } catch(error) {
    console.log(error)
  }

  const photoEnregistrer = await enregistreImage(photoRecuperer);
  return photoEnregistrer.data;
}

my application will always crash without being able to catch an error or stop the process

Other Technical Details

"@ionic/vue": "^6.7.5" "vue": "3.3.8"

We also use Sentry for capacitor, which is also unable to catch any errors. "@sentry/capacitor": "0.14.0"

Additional Context

This bug is completely random and seems to come from the native code launched by getPhoto() on the most recent phones. We do not generate the error on the iOS simulator.

corentincouq avatar Nov 07 '23 16:11 corentincouq

I have the problem, it does not seems to crash but the phone is heating and the app is not responding. It seems to be reproducible when I uninstall/reinstall the app and try to take a photo.

jpolo avatar Nov 15 '23 09:11 jpolo

Some someone pls post an error pls? Breakpoint on uncaught exceptions in xcode

jpike88 avatar May 06 '24 07:05 jpike88

Hi @robingenz and @carlpoole

my ionic 6 and capacitor 4 app crash when take picture from camera(iOS and Android). It happend only sometime like after 10 click photo app will crash, not all the time. Is it possible to fix that if we upgrade to Capacitor 5 version?

anusha-kaparapu avatar Jun 14 '24 06:06 anusha-kaparapu