ionic-team / capacitor-plugins

Official plugins for Capacitor ⚡️
482 stars 561 forks source link

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

Open corentincouq opened 7 months ago

corentincouq commented 7 months ago

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.

jpolo commented 7 months ago

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.

jpike88 commented 1 month ago

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

anusha-kaparapu commented 1 week ago

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?