Committed by
GitHub
Merge pull request #781 from navaronbracke/fix_issue_720
fix: Guard against a nil device in the background queue
Showing
1 changed file
with
13 additions
and
3 deletions
| @@ -214,18 +214,28 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega | @@ -214,18 +214,28 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega | ||
| 214 | print("Failed to reset zoom scale") | 214 | print("Failed to reset zoom scale") |
| 215 | } | 215 | } |
| 216 | 216 | ||
| 217 | - let dimensions = CMVideoFormatDescriptionGetDimensions(self.device.activeFormat.formatDescription) | 217 | + if let device = self.device { |
| 218 | + let dimensions = CMVideoFormatDescriptionGetDimensions( | ||
| 219 | + device.activeFormat.formatDescription) | ||
| 220 | + let hasTorch = device.hasTorch | ||
| 218 | 221 | ||
| 219 | DispatchQueue.main.async { | 222 | DispatchQueue.main.async { |
| 220 | completion( | 223 | completion( |
| 221 | MobileScannerStartParameters( | 224 | MobileScannerStartParameters( |
| 222 | width: Double(dimensions.height), | 225 | width: Double(dimensions.height), |
| 223 | height: Double(dimensions.width), | 226 | height: Double(dimensions.width), |
| 224 | - hasTorch: self.device.hasTorch, | ||
| 225 | - textureId: self.textureId | 227 | + hasTorch: hasTorch, |
| 228 | + textureId: self.textureId ?? 0 | ||
| 226 | ) | 229 | ) |
| 227 | ) | 230 | ) |
| 228 | } | 231 | } |
| 232 | + | ||
| 233 | + return | ||
| 234 | + } | ||
| 235 | + | ||
| 236 | + DispatchQueue.main.async { | ||
| 237 | + completion(MobileScannerStartParameters()) | ||
| 238 | + } | ||
| 229 | } | 239 | } |
| 230 | } | 240 | } |
| 231 | 241 |
-
Please register or login to post a comment