Navaron Bracke
Committed by GitHub

Merge pull request #781 from navaronbracke/fix_issue_720

fix: Guard against a nil device in the background queue
... ... @@ -214,18 +214,28 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega
print("Failed to reset zoom scale")
}
let dimensions = CMVideoFormatDescriptionGetDimensions(self.device.activeFormat.formatDescription)
if let device = self.device {
let dimensions = CMVideoFormatDescriptionGetDimensions(
device.activeFormat.formatDescription)
let hasTorch = device.hasTorch
DispatchQueue.main.async {
completion(
MobileScannerStartParameters(
width: Double(dimensions.height),
height: Double(dimensions.width),
hasTorch: self.device.hasTorch,
textureId: self.textureId
hasTorch: hasTorch,
textureId: self.textureId ?? 0
)
)
}
return
}
DispatchQueue.main.async {
completion(MobileScannerStartParameters())
}
}
}
... ...