Skip to content

Commit

Permalink
Fixed iOS NSRangeException when zooming
Browse files Browse the repository at this point in the history
Error was 'index 18446744073709551615 beyond bounds [0 .. 0]'
for RealCamera.defaultZoomFactor
  • Loading branch information
scarlac committed Aug 5, 2023
1 parent 80052ea commit 925816f
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions ios/ReactNativeCameraKit/RealCamera.swift
Original file line number Diff line number Diff line change
Expand Up @@ -489,13 +489,14 @@ class RealCamera: NSObject, CameraProtocol, AVCaptureMetadataOutputObjectsDelega
}

private func defaultZoomFactor(for videoDevice: AVCaptureDevice) -> CGFloat {
// Devices that have multiple physical cameras are binded behind one virtual camera input. The zoom factor defines what physical camera it actually uses
// Find the 'normal' zoom factor, which on the physical camera defaults to the wide angle
// Devices that have multiple physical cameras are hidden behind one virtual camera input. The zoom factor defines what physical camera it actually uses
// Find the 'normal' zoom factor, which on the native camera app defaults to the wide angle
if #available(iOS 13.0, *) {
if let indexOfWideAngle = videoDevice.constituentDevices.firstIndex(where: { $0.deviceType == .builtInWideAngleCamera }) {
if let wideAngleIndex = videoDevice.constituentDevices.firstIndex(where: { $0.deviceType == .builtInWideAngleCamera }) {
// .virtualDeviceSwitchOverVideoZoomFactors has the .constituentDevices zoom factor which borders the NEXT device
// so we grab the one PRIOR to the wide angle to get the wide angle's zoom factor
return videoDevice.virtualDeviceSwitchOverVideoZoomFactors[indexOfWideAngle - 1].doubleValue
let wideAnglePriorIndex = wideAngleIndex >= 1 ? wideAngleIndex - 1 : 0
return videoDevice.virtualDeviceSwitchOverVideoZoomFactors[wideAnglePriorIndex].doubleValue
}
}

Expand Down

0 comments on commit 925816f

Please sign in to comment.