journeyapps / zxing-android-embedded

Barcode scanner library for Android, based on the ZXing decoder
https://journeyapps.com/
Apache License 2.0
5.78k stars 1.27k forks source link

java.lang.IllegalStateException: containerSize or previewSize is not set yet #535

Open yegemberdin opened 4 years ago

yegemberdin commented 4 years ago

'com.journeyapps:zxing-android-embedded:3.6.0'

I have such kind of error in my crashlytics report and It is only in this phone: Xiaomi Mi A2, Android 9

Fatal Exception: java.lang.IllegalStateException: containerSize or previewSize is not set yet at com.journeyapps.barcodescanner.CameraPreview.calculateFrames(CameraPreview.java:369) at com.journeyapps.barcodescanner.CameraPreview.previewSized(CameraPreview.java:469) at com.journeyapps.barcodescanner.CameraPreview.access$300(CameraPreview.java:60) at com.journeyapps.barcodescanner.CameraPreview$3.handleMessage(CameraPreview.java:200) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6692) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

How to solve this???

rkistner commented 4 years ago
  1. Try upgrading to the latest version (currently 4.1.0) - some crashes have been fixed.

  2. Rare crashes are generally not worth fixing, unless the cause is obvious. If you see a lot of reports, or have a way to reproduce the issue, we can investigate further.

nenick commented 3 years ago

I found following scenario to reproduce this issue. Version 4.2.0

Set a breakpoint in com.journeyapps.barcodescanner.camera.CameraInstance on line 215 readyHandler.obtainMessage(R.id.zxing_prewiew_size_ready, getPreviewSize()).sendToTarget(); When the breakpoint is reached, then close/recreate the fragment/activity which calls pause and clears necessary fields. Then proceed from breakpoint, issue will show up.

I got no live reports yet, only my tests where running into this issue, because of fast open and close actions. Looks like this is no real issue, because the camera instance is not relevant anymore. But at this moment it would crash the app and I haven't found a way to catch this exception.

I think an option could be to have a paused flag somewhere to avoid this crash situation.

hram commented 6 months ago

@rkistner any updates on this issue?

I have the same crashes but for the new version 4.3.0

Fatal Exception: java.lang.IllegalStateException: containerSize or previewSize is not set yet at com.journeyapps.barcodescanner.CameraPreview.calculateFrames(CameraPreview.java:366) at com.journeyapps.barcodescanner.CameraPreview.previewSized(CameraPreview.java:472) at com.journeyapps.barcodescanner.CameraPreview.access$300(CameraPreview.java:60) at com.journeyapps.barcodescanner.CameraPreview$3.handleMessage(CameraPreview.java:202) at android.os.Handler.dispatchMessage(Handler.java:98) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6119) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)