Skip to content
This repository has been archived by the owner on Oct 10, 2020. It is now read-only.

[Bug] Barcode Crash on scan() #226

Closed
EArminjon opened this issue May 1, 2020 · 10 comments · Fixed by #228
Closed

[Bug] Barcode Crash on scan() #226

EArminjon opened this issue May 1, 2020 · 10 comments · Fixed by #228
Labels

Comments

@EArminjon
Copy link

EArminjon commented May 1, 2020

Describe the bug
My emulator crash when use BarcodeScanner.scan();

Screenshots
If applicable, add screenshots to help explain your problem.

Logs

V/CameraPreview( 3507): Cancelling autofocus
D/AndroidRuntime( 3507): Shutting down VM
E/AndroidRuntime( 3507): FATAL EXCEPTION: main
E/AndroidRuntime( 3507): Process: net.beyondgravity.enterprises.enterprises, PID: 3507
E/AndroidRuntime( 3507): java.lang.RuntimeException: cancelAutoFocus failed
E/AndroidRuntime( 3507): 	at android.hardware.Camera.native_cancelAutoFocus(Native Method)
E/AndroidRuntime( 3507): 	at android.hardware.Camera.cancelAutoFocus(Camera.java:1275)
E/AndroidRuntime( 3507): 	at me.dm7.barcodescanner.core.CameraPreview.setAutoFocus(CameraPreview.java:289)
E/AndroidRuntime( 3507): 	at me.dm7.barcodescanner.core.BarcodeScannerView.setAutoFocus(BarcodeScannerView.java:296)
E/AndroidRuntime( 3507): 	at de.mintware.barcode_scan.ZXingAutofocusScannerView.setAutoFocus(ZXingAutofocusScannerView.kt:26)
E/AndroidRuntime( 3507): 	at me.dm7.barcodescanner.core.BarcodeScannerView.setupCameraPreview(BarcodeScannerView.java:190)
E/AndroidRuntime( 3507): 	at de.mintware.barcode_scan.ZXingAutofocusScannerView.setupCameraPreview(ZXingAutofocusScannerView.kt:22)
E/AndroidRuntime( 3507): 	at me.dm7.barcodescanner.core.CameraHandlerThread$1$1.run(CameraHandlerThread.java:31)
E/AndroidRuntime( 3507): 	at android.os.Handler.handleCallback(Handler.java:751)
E/AndroidRuntime( 3507): 	at android.os.Handler.dispatchMessage(Handler.java:95)
E/AndroidRuntime( 3507): 	at android.os.Looper.loop(Looper.java:154)
E/AndroidRuntime( 3507): 	at android.app.ActivityThread.main(ActivityThread.java:6077)
E/AndroidRuntime( 3507): 	at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 3507): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
E/AndroidRuntime( 3507): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)

Environment :

  • Android emulator, custom (tablet) like : 800x1280 mdpi API 24 Android 7.0 x86
  • Flutter channel stable : v1.12.13+hotfix.9
  • barcode_scan: ^3.0.0
@EArminjon EArminjon added the bug label May 1, 2020
@EArminjon
Copy link
Author

I clone git@github.com:mintware-de/flutter_barcode_reader.git and run the example on my emulator, same issue...

  • Android emulator, custom (tablet) like : 800x1280 mdpi API 24 Android 7.0 x86
  • Flutter channel stable : v1.12.13+hotfix.9
  • barcode_scan: ^3.0.0

@EArminjon
Copy link
Author

EArminjon commented May 1, 2020

I test several emulator, app work when api >= 27 (Android 8.1)...

@subinsv
Copy link

subinsv commented May 2, 2020

Looks like this issue is related to
dm77/barcodescanner#208

@prokons
Copy link

prokons commented May 3, 2020

I'm having same problem on API 23 emulator.
I see that dm77/barcodescanner#208 is an old issue and it seems no one is looking at that.

@prokons
Copy link

prokons commented May 4, 2020

In kotlin class ZXingAutofocusScannerView I inserted a try-catch to bypass error

    override fun setAutoFocus(state: Boolean) {
        try {
            super.setAutoFocus(callbackFocus)
        } catch (ex: Exception) {
        }
    }

It's just a workaround and actually I don't know if this create any other problem but now app isn't crashing anymore on cancelAutoFocus and it seems it's running smooth.

@devtronic
Copy link
Member

@prokons feel free to create a PR

@oznecniV97
Copy link
Contributor

oznecniV97 commented May 4, 2020

I have the same problem on an eumlated AVD device (API 24).
I found this solution:

//solution found on https://stackoverflow.com/a/9127845/6395540
Camera.Parameters p = mCamera.getParameters();
List<String> focusModes = p.getSupportedFocusModes();

if(focusModes != null && focusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO)) {
    //Phone supports autofocus!
}
else {
    //Phone does not support autofocus!
}

I thinkthat a good thing can be insert the control inside the method that run setAutoFocus method (ZXingAutofocusScannerView.kt:26) and print log on autofocus failure instead of throwing the exception.

@prokons
Copy link

prokons commented May 5, 2020

@oznecniV97 I think your solution is better and more complete than mine.
I just don't know how to pass mCamera to setAutoFocus method without breaking the override

@oznecniV97
Copy link
Contributor

Add the fix as merge request (#228)

@devtronic devtronic linked a pull request May 8, 2020 that will close this issue
@devtronic
Copy link
Member

Merged

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants