twostraws / CodeScanner

A SwiftUI view that is able to scan barcodes, QR codes, and more, and send back what was found.
MIT License
1.01k stars 286 forks source link

Crash when using front camera and touching the screen #64

Closed rholstad closed 2 years ago

rholstad commented 2 years ago

When using the front camera

AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .front)

an exception is raised when touching the screen as if to attempt to set the focus point. From the AVFoundation documentation:

-setFocusPointOfInterest: throws an NSInvalidArgumentException if isFocusPointOfInterestSupported returns NO

Stack trace:

Last Exception Backtrace:
0   CoreFoundation                  0x1810ad0fc __exceptionPreprocess + 220 (NSException.m:200)
1   libobjc.A.dylib                 0x1998fdd64 objc_exception_throw + 60 (objc-exception.mm:565)
2   AVFCapture                      0x19faa4230 -[AVCaptureFigVideoDevice setFocusPointOfInterest:] + 280 (AVCaptureFigVideoDevice.m:0)
3   KWI Experience                  0x104a15ed8 specialized CodeScannerView.ScannerViewController.touchesBegan(_:with:) + 496 (ScannerViewController.swift:293)
4   KWI Experience                  0x104a13f34 touchesBegan + 12 (<compiler-generated>:0)
5   KWI Experience                  0x104a13f34 @objc CodeScannerView.ScannerViewController.touchesBegan(_:with:) + 132
6   UIKitCore                       0x1836b1dd4 forwardTouchMethod + 344 (UIResponder.m:2032)
7   UIKitCore                       0x18362f3a0 -[UIWindow _sendTouchesForEvent:] + 488 (UIWindow.m:2953)
8   UIKitCore                       0x183660f48 -[UIWindow sendEvent:] + 4456 (UIWindow.m:3274)
9   UIKitCore                       0x183810e34 -[UIApplication sendEvent:] + 828 (UIApplication.m:11877)
10  UIKitCore                       0x183634140 __dispatchPreprocessedEventFromEventQueue + 7904 (UIEventDispatcher.m:2290)
11  UIKitCore                       0x183628f2c __processEventQueue + 6760 (UIEventDispatcher.m:2597)
12  UIKitCore                       0x18446fd54 updateCycleEntry + 176 (UIEventDispatcher.m:102)
13  UIKitCore                       0x183c9ab44 _UIUpdateSequenceRun + 84 (_UIUpdateSequence.mm:112)
14  UIKitCore                       0x18431784c schedulerStepScheduledMainSection + 144 (_UIUpdateCycleScheduler.m:1174)
15  UIKitCore                       0x184316e3c runloopSourceCallback + 60 (_UIUpdateCycleScheduler.m:1262)
16  CoreFoundation                  0x1810cf0d0 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28 (CFRunLoop.c:1972)
17  CoreFoundation                  0x1810dfd90 __CFRunLoopDoSource0 + 208 (CFRunLoop.c:2016)
18  CoreFoundation                  0x18101a098 __CFRunLoopDoSources0 + 268 (CFRunLoop.c:2053)
19  CoreFoundation                  0x18101f8a4 __CFRunLoopRun + 820 (CFRunLoop.c:2951)
20  CoreFoundation                  0x181033468 CFRunLoopRunSpecific + 600 (CFRunLoop.c:3268)
21  GraphicsServices                0x19cbd738c GSEventRunModal + 164 (GSEvent.c:2200)
22  UIKitCore                       0x1839d65d0 -[UIApplication _run] + 1100 (UIApplication.m:3493)
23  UIKitCore                       0x183754f74 UIApplicationMain + 364 (UIApplication.m:5047)
24  SwiftUI                         0x188cf2314 closure #1 in KitRendererCommon(_:) + 164 (UIKitApp.swift:35)
25  SwiftUI                         0x188c21508 runApp<A>(_:) + 252 (<compiler-generated>:0)
26  SwiftUI                         0x188c02cb8 static App.main() + 128 (App.swift:114)
27  KWI Experience                  0x10495abd4 $main + 24 (<compiler-generated>:10)
28  KWI Experience                  0x10495abd4 main + 36 (HierarchyView.swift:0)
29  dyld                            0x104e45aa4 start + 520 (dyldMain.cpp:879)