Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App crashes after switching cameras multiple times #8

Closed
nominalista opened this issue May 10, 2019 · 7 comments
Closed

App crashes after switching cameras multiple times #8

nominalista opened this issue May 10, 2019 · 7 comments

Comments

@nominalista
Copy link

When you try to switch cameras by clicking really fast in a switch button, the app crashes due to this exception:

E/Legacy-CameraDevice-JNI: getNativeWindow: Surface had no valid native window.
E/Legacy-CameraDevice-JNI: LegacyCameraDevice_nativeDetectSurfaceDimens: Could not retrieve native window from surface.
E/AndroidRuntime: FATAL EXCEPTION: CameraX-
    Process: com.android.example.cameraxbasic, PID: 11109
    java.lang.IllegalArgumentException: Surface was abandoned
        at android.hardware.camera2.utils.SurfaceUtils.getSurfaceSize(SurfaceUtils.java:84)
        at android.hardware.camera2.params.OutputConfiguration.<init>(OutputConfiguration.java:260)
        at android.hardware.camera2.params.OutputConfiguration.<init>(OutputConfiguration.java:145)
        at android.hardware.camera2.impl.CameraDeviceImpl.createCaptureSession(CameraDeviceImpl.java:508)
        at androidx.camera.camera2.impl.CaptureSession.open(CaptureSession.java:196)
        at androidx.camera.camera2.impl.Camera.openCaptureSession(Camera.java:535)
        at androidx.camera.camera2.impl.Camera$StateCallback.onOpened(Camera.java:743)
        at androidx.camera.core.CameraDeviceStateCallbacks$ComboDeviceStateCallback.onOpened(CameraDeviceStateCallbacks.java:99)
        at android.hardware.camera2.impl.CameraDeviceImpl$1.run(CameraDeviceImpl.java:143)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:193)
        at android.os.HandlerThread.run(HandlerThread.java:65)
     Caused by: android.hardware.camera2.legacy.LegacyExceptionUtils$BufferQueueAbandonedException
        at android.hardware.camera2.legacy.LegacyExceptionUtils.throwOnError(LegacyExceptionUtils.java:73)
        at android.hardware.camera2.legacy.LegacyCameraDevice.getSurfaceSize(LegacyCameraDevice.java:606)
        at android.hardware.camera2.utils.SurfaceUtils.getSurfaceSize(SurfaceUtils.java:82)
        at android.hardware.camera2.params.OutputConfiguration.<init>(OutputConfiguration.java:260) 
        at android.hardware.camera2.params.OutputConfiguration.<init>(OutputConfiguration.java:145) 
        at android.hardware.camera2.impl.CameraDeviceImpl.createCaptureSession(CameraDeviceImpl.java:508) 
        at androidx.camera.camera2.impl.CaptureSession.open(CaptureSession.java:196) 
        at androidx.camera.camera2.impl.Camera.openCaptureSession(Camera.java:535) 
        at androidx.camera.camera2.impl.Camera$StateCallback.onOpened(Camera.java:743) 
        at androidx.camera.core.CameraDeviceStateCallbacks$ComboDeviceStateCallback.onOpened(CameraDeviceStateCallbacks.java:99) 
        at android.hardware.camera2.impl.CameraDeviceImpl$1.run(CameraDeviceImpl.java:143) 
        at android.os.Handler.handleCallback(Handler.java:873) 
        at android.os.Handler.dispatchMessage(Handler.java:99) 
        at android.os.Looper.loop(Looper.java:193) 
        at android.os.HandlerThread.run(HandlerThread.java:65) 

To reproduce this issue just run the app and tap switch button multiple times (like 15-20). I know this is not production ready app and tapping so many times fakes user behavior, but I have encountered the same issue in my own implementation just because of fragment replacing. It would be much appreciated if someone give a clue or some explanation of this issue.

@owahltinez
Copy link
Contributor

@nominalista what device are you experiencing this in?

@nominalista
Copy link
Author

@owahltinez Pixel 3.

@owahltinez
Copy link
Contributor

Unfortunately this is an error happening inside of CameraX which cannot be (easily) caught by the app. If I'm reading the logs correctly, it could be caused by the camera session sending frames to a surface that has been recycled.

Based on the behavior that you described, a workaround could be to prevent users from switching fragments until the session has been properly started. For example, keeping the button disabled until preview starts.

I'll work on getting a reliable way to reproduce this on our side, and see if we can add the workaround to the sample as well.

@owahltinez
Copy link
Contributor

@nominalista I am not able to reproduce this issue on a Pixel 3 XL. I tried pressing the switch button 15-20 times very fast, not giving the preview enough time to load; then a little slower, immediately after preview is shown; and then even slower, every 2-3 seconds.

Unfortunately I have been unable to test on the emulator due to #9

@owahltinez
Copy link
Contributor

Now that #9 is fixed I tested on the emulator but I'm also unable to reproduce. Are you still able to reproduce this issue? Can you please try again with the updated sample and, if it still crashes, share what OS build your Pixel 3 is running?

@nominalista
Copy link
Author

Sorry for late response, this video shows the issue.
After update everything works fine. Thanks and I think this issue can be closed now.

@franciscerio
Copy link

franciscerio commented Jul 3, 2019

@nominalista I think the camera is working fine. You can add some blocker/stopper when user pressed 300-400 milliseconds interval.

You can use handler.

I fixed things like this using debounce from rxbindings

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

No branches or pull requests

3 participants