Skip to content

Conversation

@Jeremy-Kr
Copy link

@Jeremy-Kr Jeremy-Kr commented Sep 26, 2025

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

- Ensure AVCaptureSession is running and video connection is both enabled + active
- Add auto-repair: re-add AVCapturePhotoOutput inside begin/commitConfiguration
- Reset session preset to .photo if available, restart session if necessary
- Add short polling window (0.5s, 50ms interval) to handle timing races
- Preserve existing logging and behavior for resolution, flash, depth, portrait effects, and distortion correction
@vercel
Copy link

vercel bot commented Sep 26, 2025

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

@Tebrynn
Copy link

Tebrynn commented Oct 9, 2025

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

@FaggioniHQ
Copy link

Hello There,

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

@isinuyk
Copy link

isinuyk commented Oct 13, 2025

+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

@sgiroux
Copy link

sgiroux commented Oct 14, 2025

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

@FelipeSchiavini
Copy link

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)

@Tebrynn
Copy link

Tebrynn commented Oct 27, 2025

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

Comment on lines -14 to 34
Takes a photo.
Captures a photo.
`takePhoto` is only available if `photo={true}`.
*/
func takePhoto(options: TakePhotoOptions, promise: Promise) {
// Run on Camera Queue
CameraQueues.cameraQueue.async {
// Get Photo Output configuration
// Validate configuration
guard let configuration = self.configuration else {
promise.reject(error: .session(.cameraNotReady))
return
}
guard configuration.photo != .disabled else {
// User needs to enable photo={true}
promise.reject(error: .capture(.photoNotEnabled))
return
}

// Check if Photo Output is available
// Validate outputs and inputs
guard let photoOutput = self.photoOutput,
let videoDeviceInput = self.videoDeviceInput else {
// Camera is not yet ready
promise.reject(error: .session(.cameraNotReady))
return
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is AI - why did you (or your AI) remove/change those comments?

path: options.path,
cameraSessionDelegate: self.delegate
)
photoOutput.capturePhoto(with: photoSettings, delegate: photoCaptureDelegate)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry but this PR is way too many changes/lines for that simple of a fix.

I think all you'd need to do is add a simple guard above photoOutput.capturePhoto(with: ..., delegate: ...) to ensure the photoOutput has a valid .video connection. 3 lines of code max.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

7 participants