Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
corentincouq opened this issue Nov 7, 2023 · 3 comments
Open

Comments

@corentincouq
Copy link

corentincouq commented Nov 7, 2023

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
Copy link

jpolo commented Nov 15, 2023

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
Copy link

jpike88 commented May 6, 2024

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

@anusha-kaparapu
Copy link

anusha-kaparapu commented Jun 14, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants