react-native-vision-camera icon indicating copy to clipboard operation
react-native-vision-camera copied to clipboard

fix(ios): prevent crash when capturePhoto has no active video connection

Open Jeremy-Kr opened this issue 3 months ago • 7 comments

What

This PR fixes a crash on iOS devices where calling AVCapturePhotoOutput.capturePhoto(with:delegate:) could throw:

*** -[AVCapturePhotoOutput capturePhotoWithSettings:delegate:] No active and enabled video connection

The crash was caused by attempting to capture a photo when the AVCaptureSession was running but the video connection was not yet active (e.g., right after camera switch, format change, or session interruption).

Changes

  • Added a readiness check before capture:
    • Ensure AVCaptureSession.isRunning == true
    • Ensure video connection is both enabled and active
  • Added an auto-repair path:
    • Re-add AVCapturePhotoOutput inside beginConfiguration/commitConfiguration
    • Reset session preset to .photo if available
    • Restart the session if necessary
  • Added a short polling window (default 0.5s, every 50ms) to handle timing races after reconfiguration
  • Preserved existing logging (VisionLogger.log) and behavior for resolution, flash, red-eye reduction, depth data, portrait effects matte, and distortion correction.

Tested on

  • iPhone 17 Pro (iOS 18 beta) – verified crash no longer occurs when switching cameras rapidly and capturing immediately.
  • iPhone 16 Pro (iOS 26.0) - regression check, normal behavior.
  • iPhone 16 Pro (iOS 18.6) - regression check, normal behavior.
  • iPhone 16 (iOS 26.0) - regression check, normal behavior.
  • iPhone 12 Pro (iOS 16.x) – regression check, normal behavior.

Related issues

  • Closes #3633
  • Related discussions:
    • https://stackoverflow.com/questions/78212727
    • https://stackoverflow.com/questions/67804126

Jeremy-Kr avatar Sep 26 '25 09:09 Jeremy-Kr

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
react-native-vision-camera Ready Ready Preview Comment Sep 26, 2025 9:03am

vercel[bot] avatar Sep 26 '25 09:09 vercel[bot]

Could you please approve this update? i cannot take photo on iphone17 pro

Tebrynn avatar Oct 09 '25 07:10 Tebrynn

Hello There,

Same here...we are getting reports about this... thanks in advance

FaggioniHQ avatar Oct 09 '25 19:10 FaggioniHQ

+1

When can we expect it to be merged and released?

We need to know whether to patch it or wait for the official fix

isinuyk avatar Oct 13 '25 13:10 isinuyk

Running into multiple instances of this as well. Do we have an ETA or is it worth patching ourselves?

sgiroux avatar Oct 14 '25 21:10 sgiroux

I created a patch using this code. The camera on the iPhone 17 Pro now works, but the preview appears significantly darker than usual before capturing the photo. with this error:

session/camera-not-ready: The Camera is not ready yet! Wait for the onInitialized() callback!
    at construct (native)
    at apply (native)
    at _construct (app:///main.jsbundle:1:255616)
    at Wrapper (app:///main.jsbundle:1:255268)
    at construct (native)
    at _callSuper (app:///main.jsbundle:1:3318079)
    at CameraError (app:///main.jsbundle:1:3318524)
    at construct (native)
    at _callSuper (app:///main.jsbundle:1:3318079)
    at CameraRuntimeError (app:///main.jsbundle:1:3318975)
    at tryParseNativeCameraError (app:///main.jsbundle:1:3319280)
    at ?anon_0_ (app:///main.jsbundle:1:3314080)
    at throw (native)
    at asyncGeneratorStep (app:///main.jsbundle:1:727134)
    at _throw (app:///main.jsbundle:1:727438)
    at tryCallOne (app:///main.jsbundle:1:1181)
    at anonymous (app:///main.jsbundle:1:1875)

FelipeSchiavini avatar Oct 27 '25 20:10 FelipeSchiavini

Camera is not darker on my iphone 17 pro but foggy and desaturated.

Tebrynn avatar Oct 27 '25 20:10 Tebrynn

@mrousavy is there an upcoming fix for this? it's crashing for ios 17 pros

jeemercado avatar Dec 16 '25 11:12 jeemercado

..did you read my review comments?

mrousavy avatar Dec 16 '25 11:12 mrousavy

..did you read my review comments?

I did but I'm not the original author. That's why I was wondering if this would be officially fixed.

jeemercado avatar Dec 16 '25 13:12 jeemercado