Redth / ZXing.Net.Mobile

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

Random crash on Android - getParameters failed (empty parameters) #924

Open RhomGit opened 4 years ago

RhomGit commented 4 years ago

ZXing.Net.Mobile v3.0.0-beta5 Android 9.0 - API 28 Debugging on physical device via USB, Samsung Galaxy S8+ with Torch on.

I entered scan mode and reached over my desk to get something with a barcode. I looked up at my screen, app had crashed. Managed to get this output.

I can't replicate it but it might be a simple one to handle so it doesn't randomly crash peoples apps.

07-22 08:31:07.251 D/ZXing.Net.Mobile(22486): Checking Number of cameras... 07-22 08:31:07.252 D/ZXing.Net.Mobile(22486): Found 2 cameras... 07-22 08:31:07.255 D/ZXing.Net.Mobile(22486): Found Back Camera, opening... 07-22 08:31:07.258 E/Camera_APM : (22486): [APM]APM's Thread is started 07-22 08:31:07.262 E/Camera_APM : (22486): [APM] This app is forground app 07-22 08:31:08.011 D/ZXing.Net.Mobile(22486): Selected Resolution: 960x720 07-22 08:31:08.018 D/ZXing.Net.Mobile(22486): Changing Camera Orientation to: 180 07-22 08:31:08.237 D/SurfaceView(22486): show() 07-22 08:31:08.251 D/SurfaceView(22486): surfaceChanged (2094,891) 1 #5 crc6480997b3ef81bf9b2.ZXingSurfaceView{93190d5 V.E...... ......ID 0,0-2094,891 #7c} 07-22 08:31:08.296 I/OpenGLRenderer(22486): Davey! duration=1428ms; Flags=1, IntendedVsync=1487089529651695, Vsync=1487089579651693, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=1487089583023162, AnimationStart=1487089583161316, PerformTraversalsStart=1487089583163047, DrawStart=1487090932708354, SyncQueued=1487090936351238, SyncStart=1487090936453738, IssueDrawCommandsStart=1487090940576123, SwapBuffers=1487090957041546, FrameCompleted=1487090958181854, DequeueBufferDuration=10016000, QueueBufferDuration=508000, 07-22 08:31:08.299 D/ViewRootImpl@dffda6mainactivity: MSG_RESIZED_REPORT: frame=Rect(0, 0 - 2220, 1080) ci=Rect(126, 63 - 0, 0) vi=Rect(126, 63 - 0, 0) or=2 07-22 08:31:08.301 D/ViewRootImpl@dffda6mainactivity: MSG_RESIZED_REPORT: frame=Rect(0, 0 - 2220, 1080) ci=Rect(126, 63 - 0, 0) vi=Rect(126, 63 - 0, 0) or=2 07-22 08:31:08.302 I/Choreographer(22486): Skipped 76 frames! The application may be doing too much work on its main thread. Java.Lang.RuntimeException: getParameters failed (empty parameters) at Java.Interop.JniEnvironment+InstanceMethods.CallObjectMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue args) [0x0006e] in :0 at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualObjectMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue parameters) [0x0002a] in :0 at Android.Hardware.Camera.GetParameters () [0x0000a] in :0 at ZXing.Mobile.CameraAccess.CameraAnalyzer.DecodeFrame (ApxLabs.FastAndroidCamera.FastJavaByteArray fastArray) [0x00000] in D:\a\ZXing.Net.Mobile\ZXing.Net.Mobile\ZXing.Net.Mobile\Android\CameraAccess\CameraAnalyzer.android.cs:111 at ZXing.Mobile.CameraAccess.CameraAnalyzer+<>c__DisplayClass24_0.b__0 () [0x00000] in D:\a\ZXing.Net.Mobile\ZXing.Net.Mobile\ZX ing.Net.Mobile\Android\CameraAccess\CameraAnalyzer.android.cs:96 --- End of managed Java.Lang.RuntimeException stack trace --- java.lang.RuntimeException: getParameters failed (empty parameters) at android.hardware.Camera.native_getParameters(Native Method) at android.hardware.Camera.getParameters(Camera.java:2133)

abosquet commented 4 years ago

I cannot reproduce it by myself but we have exactly the same issue for a couple of users.

Crash with these phones:

Stack from Crashlytics:

Fatal Exception: crc64fe7e538dcffb0c36.MonoExceptionHelper: (RuntimeException) getParameters failed (empty parameters)
       at Java.Interop.JniEnvironment+InstanceMethods.CallObjectMethod(Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args)[0x0006e](JniEnvironmentInstanceMethods0x0006e.cs:1)
       at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualObjectMethod(System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters)[0x0002a](JniPeerMembersJniInstanceMethods0x0002a.cs:1)
       at Android.Hardware.Camera.GetParameters()[0x0000a](Camera0x0000a.cs:1)
       at ZXing.Mobile.CameraAccess.CameraController.ApplyCameraSettings()[0x0001d](CameraController0x0001d.cs:1)
       at ZXing.Mobile.CameraAccess.CameraController.RefreshCamera()[0x00009](CameraController0x00009.cs:1)
       at ZXing.Mobile.CameraAccess.CameraAnalyzer.RefreshCamera()[0x00000](CameraAnalyzer0x00000.cs:1)
       at ZXing.Mobile.ZXingSurfaceView.SurfaceChanged(Android.Views.ISurfaceHolder holder, Android.Graphics.Format format, System.Int32 wx, System.Int32 hx)[0x00007](ZXingSurfaceView0x00007.cs:1)
       at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0(System.Object state)[0x00000](AsyncMethodBuilderCorec0x00000.cs:1)
       at Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0()[0x00000](SyncContextc__DisplayClass2_00x00000.cs:1)
       at Java.Lang.Thread+RunnableImplementor.Run()[0x00008](ThreadRunnableImplementor0x00008.cs:1)
       at Java.Lang.IRunnableInvoker.n_Run(System.IntPtr jnienv, System.IntPtr native__this)[0x00009](IRunnableInvoker0x00009.cs:1)
       at   at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.47(intptr,intptr).(unknown.cs:1)
       at   --- End of managed Java.Lang.RuntimeException stack trace ---.(unknown.cs:1)
       at java.lang.RuntimeException: getParameters failed (empty parameters).(unknown.cs:1)
       at   at android.hardware.Camera.native_getParameters(Native Method).(unknown.cs:1)
       at   at android.hardware.Camera.getParameters(Camera.java:2132).(unknown.cs:1)
       at   at crc6480997b3ef81bf9b2.ZXingSurfaceView.n_surfaceChanged(Native Method).(unknown.cs:1)
       at   at crc6480997b3ef81bf9b2.ZXingSurfaceView.surfaceChanged(ZXingSurfaceView.java:84).(unknown.cs:1)
       at   at android.view.SurfaceView.updateSurface(SurfaceView.java:942).(unknown.cs:1)
       at   at android.view.SurfaceView$2.onPreDraw(SurfaceView.java:215).(unknown.cs:1)
       at   at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:1102).(unknown.cs:1)
       at   at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3310).(unknown.cs:1)
       at   at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2200).(unknown.cs:1)
       at   at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:9065).(unknown.cs:1)
       at   at android.view.Choreographer$CallbackRecord.run(Choreographer.java:999).(unknown.cs:1)
       at   at android.view.Choreographer.doCallbacks(Choreographer.java:797).(unknown.cs:1)
       at   at android.view.Choreographer.doFrame(Choreographer.java:732).(unknown.cs:1)
       at   at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:984).(unknown.cs:1)
       at   at android.os.Handler.handleCallback(Handler.java:883).(unknown.cs:1)
       at   at android.os.Handler.dispatchMessage(Handler.java:100).(unknown.cs:1)
       at   at android.os.Looper.loop(Looper.java:237).(unknown.cs:1)
       at   at android.app.ActivityThread.main(ActivityThread.java:8016).(unknown.cs:1)
       at   at java.lang.reflect.Method.invoke(Native Method).(unknown.cs:1)
       at   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493).(unknown.cs:1)
       at   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1076).(unknown.cs:1)
breenbob commented 4 years ago

Same issue here and with same stack trace, and we are using the latest pre-release version (3.0.0 beta 5) as recommended in the original issue here. Any update on this?

breenbob commented 4 years ago

Same reason for closing and lack of any discernible fix on this issue which also seems related. A workaround has been suggested on that thread by one user, though.

Jakar510 commented 4 years ago

I'm getting this too.

Jakar510 commented 4 years ago

@Redth @abosquet

I also get a crash with a Samsung Galaxy Note 10+.

**Java.Lang.RuntimeException:** 'getParameters failed (empty parameters)'
07-28 15:04:06.719 I/MonoDroid(11728): UNHANDLED EXCEPTION:
07-28 15:04:06.723 I/MonoDroid(11728): Java.Lang.RuntimeException: getParameters failed (empty parameters)
07-28 15:04:06.724 I/MonoDroid(11728):   at Java.Interop.JniEnvironment+InstanceMethods.CallObjectMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0006e] in <9324da45a6654f83baffa7c2854d836a>:0 
07-28 15:04:06.724 I/MonoDroid(11728):   at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualObjectMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0002a] in <9324da45a6654f83baffa7c2854d836a>:0 
07-28 15:04:06.724 I/MonoDroid(11728):   at Android.Hardware.Camera.GetParameters () [0x0000a] in <eaa205f580954a64824b74a79fa87c62>:0 
07-28 15:04:06.724 I/MonoDroid(11728):   at ZXing.Mobile.CameraAccess.CameraController.ApplyCameraSettings () [0x00017] in D:\a\ZXing.Net.Mobile\ZXing.Net.Mobile\ZXing.Net.Mobile\Android\CameraAccess\CameraController.android.cs:226 
07-28 15:04:06.724 I/MonoDroid(11728):   at ZXing.Mobile.CameraAccess.CameraController.RefreshCamera () [0x00009] in D:\a\ZXing.Net.Mobile\ZXing.Net.Mobile\ZXing.Net.Mobile\Android\CameraAccess\CameraController.android.cs:41 
07-28 15:04:06.724 I/MonoDroid(11728):   at ZXing.Mobile.CameraAccess.CameraAnalyzer.RefreshCamera () [0x00000] in D:\a\ZXing.Net.Mobile\ZXing.Net.Mobile\ZXing.Net.Mobile\Android\CameraAccess\CameraAnalyzer.android.cs:58 
07-28 15:04:06.724 I/MonoDroid(11728):   at ZXing.Mobile.ZXingSurfaceView.OnWindowFocusChanged (System.Boolean hasWindowFocus) [0x00025] in D:\a\ZXing.Net.Mobile\ZXing.Net.Mobile\ZXing.Net.Mobile\Android\ZXingSurfaceView.android.cs:157 
07-28 15:04:06.724 I/MonoDroid(11728):   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1021 
07-28 15:04:06.724 I/MonoDroid(11728):   at Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0 () [0x00000] in <eaa205f580954a64824b74a79fa87c62>:0 
07-28 15:04:06.724 I/MonoDroid(11728):   at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <eaa205f580954a64824b74a79fa87c62>:0 
07-28 15:04:06.724 I/MonoDroid(11728):   at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in <eaa205f580954a64824b74a79fa87c62>:0 
07-28 15:04:06.724 I/MonoDroid(11728):   at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.1(intptr,intptr)
07-28 15:04:06.724 I/MonoDroid(11728):   --- End of managed Java.Lang.RuntimeException stack trace ---
07-28 15:04:06.724 I/MonoDroid(11728): java.lang.RuntimeException: getParameters failed (empty parameters)
07-28 15:04:06.724 I/MonoDroid(11728):  at android.hardware.Camera.native_getParameters(Native Method)
07-28 15:04:06.724 I/MonoDroid(11728):  at android.hardware.Camera.getParameters(Camera.java:2132)
07-28 15:04:06.724 I/MonoDroid(11728):  at crc6480997b3ef81bf9b2.ZXingSurfaceView.n_onWindowFocusChanged(Native Method)
07-28 15:04:06.724 I/MonoDroid(11728):  at crc6480997b3ef81bf9b2.ZXingSurfaceView.onWindowFocusChanged(ZXingSurfaceView.java:84)
07-28 15:04:06.724 I/MonoDroid(11728):  at android.view.View.dispatchWindowFocusChanged(View.java:14657)
07-28 15:04:06.724 I/MonoDroid(11728):  at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:1502)
07-28 15:04:06.724 I/chatty  (11728): uid=10701(com.TrueLogicCompany.iTrueLogic) identical 17 lines
07-28 15:04:06.724 I/MonoDroid(11728):  at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:1502)
07-28 15:04:06.724 I/MonoDroid(11728):  at android.view.ViewRootImpl.handleWindowFocusChanged(ViewRootImpl.java:3454)
07-28 15:04:06.724 I/MonoDroid(11728):  at android.view.ViewRootImpl.access$1300(ViewRootImpl.java:205)
07-28 15:04:06.724 I/MonoDroid(11728):  at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:5357)
07-28 15:04:06.724 I/MonoDroid(11728):  at android.os.Handler.dispatchMessage(Handler.java:107)
07-28 15:04:06.724 I/MonoDroid(11728):  at android.os.Looper.loop(Looper.java:237)
07-28 15:04:06.724 I/MonoDroid(11728):  at android.app.ActivityThread.main(ActivityThread.java:8034)
07-28 15:04:06.724 I/MonoDroid(11728):  at java.lang.reflect.Method.invoke(Native Method)
07-28 15:04:06.724 I/MonoDroid(11728):  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
07-28 15:04:06.724 I/MonoDroid(11728):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1076)

@Breenbob I tried the workaround. It did work. Thank you.

knocte commented 3 years ago

Hey guys, do you also get this crash with v2.4.1?

abosquet commented 3 years ago

Hey guys, do you also get this crash with v2.4.1?

It's not an option for us because we have to use ZXing.Net 0.16.5 as min version FYI as workaround in OnAppearing and OnDisappearing event I enable/disable IsScanning & IsAnalyzing properties and no crash anymore. Tested with > 1000 users.

stefanhk31 commented 3 years ago

I'm running into this exception on v2.4.1. It happens when taking a photo, then navigating to a scanner page, then navigating to take another photo. The second time a photo is taken, the exception is thrown after taking a photo and clicking to confirm the picture.

Rolling back to 2.3.2 seems to have done the trick.

janoosthoek commented 3 years ago

Confirmed here as well on v2.4.1 have not tried any workaround yet. But it appears to be related to OnAppearing and OnDisappearing events.

note: ios appears to be fine.

knocte commented 3 years ago

If 2.3.2 works and 2.4.1 doesn't, can someone bisect it please?

MartinRobins commented 3 years ago

Sorry to disappoint folks, but confirmed here on 2.3.2 also.

I fear however that no action is to be taken unless it is reproduced within one of the 3.x beta versions. Would like to know how "beta" these beta versions are given that they have gone from 3.0.x to 3.1.x with every version in between being marked as beta.

Additionally, it would appear that nobody has been replying to any issues since January which is also worrying for the future of the project.

Jakar510 commented 3 years ago

This occurs for me on 3.0.0 beta 5 and 3.1.0 beta*.

breyed commented 3 years ago

On 3.1.0 beta, this crash still occurs in the field, even if IsScanning and IsAnalyzing are set false in OnAppearing.

PlaysafePP commented 1 year ago

I also am getting this issue using the latest ZXing 3.1.0-beta2

My Xamarin.Forms 5 app was seemingly working fine previously using FreshMvvm, but I have now changed it to a shell application. It seems to me I get this error (callstack is only 1 deep and shows "external code") when the page is not even the current page (have moved to a different page via Shell.Current.GotoAsync). The problem is definitely emitted from my ZXing library as it doesn't happen if I remove my ZXIngScannerView from the page, it does not happen.

Searching this project's issues here in Github, I find at least 3 references to the same error (though possibly for different reasons). It was first reported in #728 in 2018. The author @Redth closed it March 2020 asking for a new issue to be opened if it still occurs.

This thread for issue #924 you are reading now was opened in July 2020, and issue 1011 was opened in August 2021. Although others have commented it still occurs in various versions of ZXing, these new reports contain no suggestions to fix, nor comments from the ZXing author.

Whilst very grateful to @Redth for the library in the first place, his continued input on the library and these posts do not seem very forthcoming. Has anybody actually solved this issue themselves? Are you aware of a fork inthe library where somebody has addressed it?

RhomGit commented 1 year ago

Hi @PlaysafePP , OP here, I never did find a resolution and eventually moved to an alternate library.

PlaysafePP commented 1 year ago

Hi @RhomGit thanks for your very quick response (I expect to wait weeks/months). It would be a shame to have to move away from ZXing, but if I had to..... what alternate did you go with?

Thanks in advance

RhomGit commented 1 year ago

I didn't want to move away either but in a production app no choice really. We have found https://github.com/JimmyPun610/BarcodeScanner.Mobile to be fast and reliable.

If/when you decide to move to MAUI there is the new ZXing project here if you wanted to remain loyal :) https://github.com/Redth/ZXing.Net.Maui

Jerome-Liger commented 1 year ago

5 years this issue persists, and it's not acceptable for our applications to CRASHE violently in production :-( As nobody move... so I will.

Related Issues : #728 #924 #1011 (and maybe more ? I stopped my search here...)

A pull request https://github.com/Redth/ZXing.Net.Mobile/pull/1002 has been kindly submitted by @rdfordatascience-ops (thanks ;-)) but has never been merged, accepted or included in a new version... It's not a "clean" solution, but it's better than CRASHES.

So :

https://www.nuget.org/packages/Respawnsive.ZXing.Net.Mobile/ https://www.nuget.org/packages/Respawnsive.ZXing.Net.Mobile.Forms/

-> 1 hour, that's all what it takes to me...

So I hope this will be usefull for some peoples... because the "real production world" is not focused on MAUI (not yet at least ;-)) Regards

Jakar510 commented 1 year ago

5 years this issue persists, and it's not acceptable for our applications to CRASHE violently in production :-( As nobody move... so I will.

Related Issues : #728 #924 #1011 (and maybe more ? I stopped my search here...)

A pull request #1002 has been kindly submitted by @rdfordatascience-ops (thanks ;-)) but has never been merged, accepted or included in a new version... It's not a "clean" solution, but it's better than CRASHES.

So :

  • I forked this repo (https://github.com/Respawnsive/ZXing.Net.Mobile)
  • I've applied the PR 1002 :

    • Just a "try-catch" block for not CRASHING our apps
    • Apparently, it continues to works normaly even after an exception raised here... (@rdfordatascience-ops you can confirm ?)
  • I've deleted some target platforms (I don't have time to install all the SDKs required for platforms that nobody use ;-)) :

    • Tizen
    • MacOS
    • Windows UAP
    • (so I only keep .netStandard/Android/iOS
  • I build successfully, generate NuGetPackages and publish them :

https://www.nuget.org/packages/Respawnsive.ZXing.Net.Mobile/ https://www.nuget.org/packages/Respawnsive.ZXing.Net.Mobile.Forms/

-> 1 hour, that's all what it takes to me...

So I hope this will be usefull for some peoples... because the "real production world" is not focused on MAUI (not yet at least ;-)) Regards

@Redth Could you update the package, please? It really does need to be fixed.