Apparence-io / CamerAwesome

📸 Embedding a camera experience within your own app shouldn't be that hard. A flutter plugin to integrate awesome Android / iOS camera experience.
https://ApparenceKit.dev
MIT License
976 stars 256 forks source link

[Crash] Crash while switching fast sensor #54

Closed mquerique closed 2 years ago

mquerique commented 3 years ago

Firstly, thanks for your work!

I've been getting a few crashes at random while trying to switch the camera sensor (Back/Front).

Steps to Reproduce

Sometimes the crash occours the first time I open the camera, but the easiest way to reproduce is to rapidly switch sensors (aka: mashing a button that toggles front/back cameras). I've tested it on 2 real devices and it's pretty consistent in one of them (Moto E5).

Stacktrace
java.lang.IllegalStateException: CameraDevice was already closed
        at android.hardware.camera2.impl.CameraDeviceImpl.checkIfCameraClosedOrInError(CameraDeviceImpl.java:2217)
        at android.hardware.camera2.impl.CameraDeviceImpl.submitCaptureRequest(CameraDeviceImpl.java:932)
        at android.hardware.camera2.impl.CameraDeviceImpl.setRepeatingRequest(CameraDeviceImpl.java:979)
        at android.hardware.camera2.impl.CameraCaptureSessionImpl.setRepeatingRequest(CameraCaptureSessionImpl.java:239)
        at com.apparence.camerawesome.CameraPreview.refreshConfiguration(CameraPreview.java:238)
        at com.apparence.camerawesome.CameraPreview.onConfigured(CameraPreview.java:284)
        at com.apparence.camerawesome.CameraSession$1.onConfigured(CameraSession.java:52)
        at java.lang.reflect.Method.invoke(Native Method)
        at android.hardware.camera2.dispatch.InvokeDispatcher.dispatch(InvokeDispatcher.java:39)
        at android.hardware.camera2.dispatch.HandlerDispatcher$1.run(HandlerDispatcher.java:65)
        at android.os.Handler.handleCallback(Handler.java:789)
        at android.os.Handler.dispatchMessage(Handler.java:98)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6694)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:769)

Expected results

Switch the camera sensor.

Actual results

App crashes

About your device

Brand Model OS
Motorola Moto E5 8.0.0
Motorola Moto G6 9

g-apparence commented 3 years ago

Yes I think we should prevent you from doing this too fast. Android when switch sensor force us to recreate everything so this can take some time depending on the device.

mquerique commented 3 years ago

The problem is that sometimes I'm gettingthe same crash as I open the app, using the "spam click" method is just a way to reproduce the error, not 100% sure that it's the only cause.

stefanodecillis commented 3 years ago

Hi,

I see that the fix has been scheduled in the activities and it will be fixed. In the meanwhile, I would like to use your this plugin but the user can change the sensor sometimes. There is some workaround for this problem?

g-apparence commented 2 years ago

You can add a debounce timer to prevent user to switch between sensors too fast yes. I close this.