Redth / ZXing.Net.Mobile

Barcode Scanner for Xamarin.iOS, Xamarin.Android, UWP and Tizen
MIT License
1.07k stars 703 forks source link

Call to Scan method crashes in Xamarin.Forms app running on iPhone from Visual Studio 2019 #975

Open tnewell opened 3 years ago

tnewell commented 3 years ago

I'm testing the iOS version of my Xamarin.Forms app on my iPhone from Visual Studio 2019 and when the code reaches the point of calling the Scan method of the MobileBarcodeScanner object, the app crashes. In particular, the screen displays the overlay and the camera is on, but no scanning happens and I get the output below. When I hit the Cancel option at the bottom of the screen, I get a return from the Scan call with a null result. My code for making the call follows the error dump and that's followed by version data. I'm using the Hot Restart feature in Visual Studio that allows me to deploy to an iPhone as long as I have iTunes running. Scanning seems to work fine on UWP and Android simulators and Android Fire tablet.

-- Start Error Dump --

`2021-01-31 22:01:01.928 Xamarin.PreBuilt.iOS[20513:3446096] Starting to scan...

2021-01-31 22:01:01.984 Xamarin.PreBuilt.iOS[20513:3446096] ZXingScannerView.Setup() took 50.176 ms. 2021-01-31 22:01:01.985 Xamarin.PreBuilt.iOS[20513:3446096] StartScanning

Thread started: #16 Thread started: #17

================================================================= Native Crash Reporting

Got a segv while executing native code. This usually indicates a fatal error in the mono runtime or one of the native libraries used by your application.

================================================================= Native stacktrace:

0x102218120 - /private/var/containers/Bundle/Application/9F407528-3DA5-4573-9F05-08FFF7A05512/SandboxXamarinApp.iOS.app/Xamarin.PreBuilt.iOS : mono_dump_native_crash_info

0x10220ecbc - /private/var/containers/Bundle/Application/9F407528-3DA5-4573-9F05-08FFF7A05512/SandboxXamarinApp.iOS.app/Xamarin.PreBuilt.iOS : mono_handle_native_crash

0x10221ba60 - /private/var/containers/Bundle/Application/9F407528-3DA5-4573-9F05-08FFF7A05512/SandboxXamarinApp.iOS.app/Xamarin.PreBuilt.iOS : mono_sigsegv_signal_handler_debug

0x1e03a9290 - /usr/lib/system/libsystem_platform.dylib : <redacted>

0x1023aa9e4 - /private/var/containers/Bundle/Application/9F407528-3DA5-4573-9F05-08FFF7A05512/SandboxXamarinApp.iOS.app/Xamarin.PreBuilt.iOS : xamarin_collapse_struct_name

0x1023b6198 - /private/var/containers/Bundle/Application/9F407528-3DA5-4573-9F05-08FFF7A05512/SandboxXamarinApp.iOS.app/Xamarin.PreBuilt.iOS : _ZL15param_iter_next14IteratorActionPvPKcmS0_Pj
0x1023aff84 - /private/var/containers/Bundle/Application/9F407528-3DA5-4573-9F05-08FFF7A05512/SandboxXamarinApp.iOS.app/Xamarin.PreBuilt.iOS : xamarin_invoke_trampoline

0x1023b6074 - /private/var/containers/Bundle/Application/9F407528-3DA5-4573-9F05-08FFF7A05512/SandboxXamarinApp.iOS.app/Xamarin.PreBuilt.iOS : xamarin_arch_trampoline

0x1023b6c18 - /private/var/containers/Bundle/Application/9F407528-3DA5-4573-9F05-08FFF7A05512/SandboxXamarinApp.iOS.app/Xamarin.PreBuilt.iOS : xamarin_arm64_common_trampoline
0x1aee19f20 - /System/Library/PrivateFrameworks/AVFCapture.framework/AVFCapture : <redacted>
0x1aee19c4c - /System/Library/PrivateFrameworks/AVFCapture.framework/AVFCapture : <redacted>

0x1aeee3844 - /System/Library/PrivateFrameworks/CMCapture.framework/CMCapture : <redacted>
0x1af15d338 - /System/Library/PrivateFrameworks/CMCapture.framework/CMCapture : <redacted>
0x1947d1db0 - /usr/lib/system/libdispatch.dylib : <redacted>
0x1947d512c - /usr/lib/system/libdispatch.dylib : <redacted>
0x1947e6c08 - /usr/lib/system/libdispatch.dylib : <redacted>
0x1947d8fd8 - /usr/lib/system/libdispatch.dylib : <redacted>
0x1947d9c5c - /usr/lib/system/libdispatch.dylib : <redacted>
0x1947e3d78 - /usr/lib/system/libdispatch.dylib : <redacted>
0x1e03af804 - /usr/lib/system/libsystem_pthread.dylib : _pthread_wqthread
0x1e03b675c - /usr/lib/system/libsystem_pthread.dylib : start_wqthread

================================================================= Basic Fault Address Reporting

Memory around native instruction pointer (0x1023aa8c4):0x1023aa8b4 a8 83 5e f8 09 00 80 52 09 01 00 39 a8 03 5f f8 ..^....R...9... 0x1023aa8c4 09 01 40 3 9 69 0f 00 34 a8 03 5f f8 09 01 c0 39 ..@9i..4......9 0x1023aa8d4 29 8d 00 71 e8 03 09 aa 08 7d 40 d3 1f 69 01 f1 )..q.....}@..i.. 0x1023aa8e4 e8 13 00 f9 68 0b 00 54 08 00 00 90 08 61 2c 91 ....h..T.....a,.

================================================================= Managed Stacktrace:

=================================================================

2021-01-31 22:01:12.694 Xamarin.PreBuilt.iOS[20513:3446096] Stopping... ` -- End Error Dump --

-- Start Code Fragment --

    private async void InvokeScanner()
    {
        try
        {
            MobileBarcodeScanner scanner = new MobileBarcodeScanner();
            MobileBarcodeScanningOptions opt = new MobileBarcodeScanningOptions()
            {
                PossibleFormats = new List<ZXing.BarcodeFormat> { ZXing.BarcodeFormat.QR_CODE },
            };

            var result = await scanner.Scan(opt);

            if (result != null)
            {
                System.Diagnostics.Debug.WriteLine(String.Format("Result = |{0}|", result.Text));

                Barcode = result.Text;
            }
        }
        catch (Exception ex)
        {
            System.Diagnostics.Debug.WriteLine(ex.ToString());
        }
    }

-- End Code Fragment --

-- Start Version Info --

iPhone XR, iOS 14.3

Visual Studio 2019 - v16.8.4 Xamarin.iOS SDK - 14.8.0.3

The shared Xamarin app is a .NET Standard 2.0 library

All parts use: Xamarin.Forms - v5.0.0.1931 Xamarin.Essentials - v1.6.1 ZXing.Net.Mobile - v3.0.0.0-beta5 ZXing.Net.Mobile.Forms - v3.0.0.0-beta5

bakerhillpins commented 3 years ago

@tnewell Update Xamarin.Forms to 5.0.0.2012 and I bet that will fix it. I had basically the same Native Stack trace and upgrading the NuGet packages across the solution removed the crash.

Nobody84 commented 3 years ago

Same problem for me for both, the stabel (2.4.1) and the current newest beta (3.1.0-beta2) version. I allready using Xamarin.Forms 5.0.0.212.

Stacktrace

Stacktrace

2021-06-02 12:23:54.291 UniversalInventory.iOS[5326:5133071] Starting to scan... 2021-06-02 12:23:54.335 UniversalInventory.iOS[5326:5133071] ZXingScannerView.Setup() took 41,221 ms. 2021-06-02 12:23:54.335 UniversalInventory.iOS[5326:5133071] StartScanning ================================================================= Native Crash Reporting ================================================================= Got a abrt while executing native code. This usually indicates a fatal error in the mono runtime or one of the native libraries used by your application. ================================================================= ================================================================= Native stacktrace: ================================================================= 0x10d6604e4 - /private/var/containers/Bundle/Application/051ED1DD-582D-456F-ADD3-BA04964BBE87/UniversalInventory.iOS.app/UniversalInventory.iOS : mono_dump_native_crash_info 0x10d656750 - /private/var/containers/Bundle/Application/051ED1DD-582D-456F-ADD3-BA04964BBE87/UniversalInventory.iOS.app/UniversalInventory.iOS : mono_handle_native_crash 0x10d65fa30 - /private/var/containers/Bundle/Application/051ED1DD-582D-456F-ADD3-BA04964BBE87/UniversalInventory.iOS.app/UniversalInventory.iOS : sigabrt_signal_handler 0x1ea1f7298 - /usr/lib/system/libsystem_platform.dylib : 0x1cc6a4a30 - /usr/lib/system/libsystem_kernel.dylib : 0x1cc6a4a64 - /usr/lib/system/libsystem_kernel.dylib : 0x1e245201c - /System/Library/PrivateFrameworks/TCC.framework/TCC : TCCAccessRequest 0x1e2452adc - /System/Library/PrivateFrameworks/TCC.framework/TCC : 0x1e24570f4 - /System/Library/PrivateFrameworks/TCC.framework/TCC : 0x1ea23017c - /usr/lib/system/libxpc.dylib : 0x1ea223aa8 - /usr/lib/system/libxpc.dylib : 0x19e345e38 - /usr/lib/system/libdispatch.dylib : 0x19e361410 - /usr/lib/system/libdispatch.dylib : 0x19e35765c - /usr/lib/system/libdispatch.dylib : 0x1ea1fd84c - /usr/lib/system/libsystem_pthread.dylib : _pthread_wqthread 0x1ea20476c - /usr/lib/system /libsystem_pthread.dylib : start_wqthread ================================================================= Basic Fault Address Reporting ================================================================= Memory around native instruction pointer (0x1cc69fb84):0x1cc69fb74 ff 0f 5f d6 c0 03 5f d6 30 41 80 d2 01 10 00 d4 .._..._.0A...... 0x1cc69fb84 03 01 00 54 7f 23 03 d5 fd 7b bf a9 fd 03 00 91 ...T.#...{...... 0x1cc69fb94 23 78 ff 97 bf 03 00 91 fd 7b c1 a8 ff 0f 5f d6 #x.......{...._. 0x1cc69fba4 c0 03 5f d6 d0 03 80 d2 01 10 00 d4 03 01 00 54 .._............T The app has been terminated.

Device

iPhone 12, iOS 14.4.2

Environment

Visual Studio 2019 - v16.9.6 Xamarin.iOS SDK - 14.16.0.5

Xamarin.Forms - v5.0.0.2012 Xamarin.Essentials - v1.6.1

ZXing.Net.Mobile - v2.4.1 / v3.1.0-beta2 ZXing.Net.Mobile.Forms - v2.4.1 / v3.1.0-beta2

Crash0 commented 3 years ago

Any updates on this?

petar-varga commented 3 years ago

I think that this might be related to using the Hot Restart feature in Visual Studio. I have ran https://github.com/jfversluis/XFScanBarcodeSample project with Hot Restart and I always got the native crash reporting stuff.

However, after deploying to iPhone device through Mac device (paired Mac device) while still in Visual Studio in Windows it seems to work properly.

Can anyone try if they get the same results on this?

EDIT: Looks like this is the issue, confirmed in this issues thread: https://github.com/Redth/ZXing.Net.Mobile/issues/967#issuecomment-782840533

DerLud3 commented 2 years ago

I got the same error. still not fixed

AshWhitear commented 2 years ago

Not sure if this helps anyone, I had this error until I added the correct permission req. for iOS in Info.plist:

<key>NSCameraUsageDescription</key>
<string>Please allow the camera to be used for scanning barcodes</string>