Status Update
Comments
er...@google.com <er...@google.com> #2
tr...@google.com <tr...@google.com> #3
Great! Thanks a lot, I'll look for the live updates soon!
sc...@google.com <sc...@google.com> #4
Yes, this crash is exactly the same crash I saw when ImageCapture.takePicture is called but ImageCapture is not bound.
Hi Reporter,
I think there might be a timing that accidentally ImageCapture is being unbound and takePicture is called.
The quick way to fix it at apps side is to add some protection like setting a flag to disable takePicture when unbinding and enable it after binding happens.
In the meanwhile CameraX probably should invoke the onError callback instead crashing directly. we will have some fixes on this.
Scott
le...@google.com <le...@google.com>
sc...@google.com <sc...@google.com> #5
It happens after 1.1.0-alpha11
We will fix it and add tests to ensure that won't happen.
sc...@google.com <sc...@google.com> #6
We need to cherrypick the fix for the next rc release.
ka...@hinge.co <ka...@hinge.co> #7
Best,
Kathleen Maas
sc...@google.com <sc...@google.com> #8
From your data, the issue definitely will cause stability issue for the app. we will do whatever we can to prevent from this kind of stability issue.
ap...@google.com <ap...@google.com> #9
Branch: androidx-main
commit 65312c90bd30f732f7246a6ff95b9b70b4fa5827
Author: leo huang <leohuang@google.com>
Date: Wed Apr 27 18:49:07 2022
Fix NullPointerException on ImageCapture.takePicture()
Exception occurs when calling ImageCapture.takePicture() but ImageCapture is not bound to the lifecycle.
Relnote: "Fixed NullPointerException on ImageCapture.takePicture()."
Bug:
Test: ./gradlew camera:camera-core:testDebug
Change-Id: I92366821320e183ca9ba4c6468325a686e6f9720
M camera/camera-core/src/main/java/androidx/camera/core/ImageCapture.java
M camera/camera-core/src/test/java/androidx/camera/core/ImageCaptureTest.kt
tr...@google.com <tr...@google.com> #10
Thank you Leo and Scott for jumping on this so quickly. Cherry-picking this fix into the next release would be great!
lo...@gmail.com <lo...@gmail.com> #12
Downgrading the camera-core dependency to 1.0.0 still reproduces the crash on Pixel 2 XL. Invalidated caches and restarted Android Studio multiple times. Any idea on what is happening ?
FWIW, working with a sample app that demos CameraX api . Verified that ImageCapture binds to lifecycle without any issues.
Deps
implementation "androidx.camera:camera-core:1.0.0"
implementation "androidx.camera:camera-camera2:1.0.2"
implementation "androidx.camera:camera-lifecycle:1.0.2"
implementation "androidx.camera:camera-video:1.1.0-rc01"
implementation "androidx.camera:camera-view:1.1.0-rc01"
implementation "androidx.camera:camera-extensions:1.1.0-rc01"
sc...@google.com <sc...@google.com> #13
In your build configuration, the actual running camera-core version will be 1.1.0-rc01 isntead of 1.0.0.
camera-video:1.1.0-rc01, camera-view:1.1.0-rc01 and camera-extensions:1.1.0-rc01 all have dependency of camera-core 1.1.0-rc01. This will override your camera-core version to 1.1.0-rc01 regardless of your camera-core version.
BTW, the issue will be fixed in 1.1.0-rc02.
ic...@gmail.com <ic...@gmail.com> #14
ic...@gmail.com <ic...@gmail.com> #15
hi i still got error, the problem is when i took the picture for the first time with ImageCapture.takePicture(Executor, ImageCapture.OnImageSavedCallback)
it worked, but for the second time and next it throw an error Not bound to a valid Camera [ImageCapture:androidx.camera.core.ImageCapture-320a0d5d-b821-41e5-afbe-1f4c15126f74]
le...@google.com <le...@google.com> #16
The error means the app take picture after lifecycle goes to stop or ImageCapture is unbound, which is not a valid operation for taking picture.
Is this the case on your app? or could you share some code snippet?
we...@google.com <we...@google.com> #17
My code snippet is the CameraX code lab. Following the instructions there, I get this exception.
we...@google.com <we...@google.com> #18
we...@google.com <we...@google.com> #19
java.lang.NullPointerException: Attempt to invoke interface method 'androidx.camera.core.impl.CameraInfoInternal androidx.camera.core.impl.CameraInternal.getCameraInfoInternal()' on a null object reference
at androidx.camera.core.UseCase.getRelativeRotation(UseCase.java:313)
at androidx.camera.core.ImageCapture.takePicture(ImageCapture.java:978)
Using cameraX 1.1.0-beta01.
sc...@google.com <sc...@google.com> #20
Please try CameraX 1.1.0. (no "-xxxx" postfix)
It should contain the fix.
we...@google.com <we...@google.com> #21
Sorry, for the comment spam, I just downgraded to 1.0.0 and it warned me about updating to 1.3.0-alpha01...
Using 1.1.0 and 1.2.0-rc01, I get:
2022-11-11 15:56:48.591 29888-29888/com.google.android.apps.gmm E/CameraXApp: Photo capture failed: Not bound to a valid Camera [ImageCapture:androidx.camera.core.ImageCapture-1d13b80a-fa5d-46e0-9e9c-eaeeab189e0d]
androidx.camera.core.ImageCaptureException: Not bound to a valid Camera [ImageCapture:androidx.camera.core.ImageCapture-1d13b80a-fa5d-46e0-9e9c-eaeeab189e0d]
at androidx.camera.core.ImageCapture.lambda$sendImageCaptureRequest$5$androidx-camera-core-ImageCapture(ImageCapture.java:1138)
at androidx.camera.core.ImageCapture$$ExternalSyntheticLambda12.run(Unknown Source:4)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7898)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Using 1.3.0-alpha01, I get:
2022-11-11 15:59:41.282 30192-30192/com.google.android.apps.gmm E/CameraXApp: Photo capture failed: Not bound to a valid Camera [ImageCapture:androidx.camera.core.ImageCapture-0e9ec1c7-dc5e-4768-8dd3-fb3ce25823ac]
androidx.camera.core.ImageCaptureException: Not bound to a valid Camera [ImageCapture:androidx.camera.core.ImageCapture-0e9ec1c7-dc5e-4768-8dd3-fb3ce25823ac]
at androidx.camera.core.ImageCapture.sendInvalidCameraError(ImageCapture.java:2005)
at androidx.camera.core.ImageCapture.takePictureWithNode(ImageCapture.java:1986)
at androidx.camera.core.ImageCapture.takePicture(ImageCapture.java:1058)
I fail to see any discrepancies between the codelab, the
we...@google.com <we...@google.com> #22
I was not binding the imageCapture
on this line:
bindToLifecycle(this@LiveCameraFragment, cameraSelector, preview, imageCapture)
Now, on an emulator, I get a different error:
2022-11-11 16:40:20.090 30654-30683/com.google.android.apps.gmm E/CameraCaptureSession: Session 0: Exception while stopping repeating:
android.hardware.camera2.CameraAccessException: CAMERA_ERROR (3): The camera device has encountered a serious error
at android.hardware.camera2.impl.CameraDeviceImpl.checkIfCameraClosedOrInError(CameraDeviceImpl.java:2429)
at android.hardware.camera2.impl.CameraDeviceImpl.stopRepeating(CameraDeviceImpl.java:1329)
at android.hardware.camera2.impl.CameraCaptureSessionImpl.close(CameraCaptureSessionImpl.java:579)
at androidx.camera.camera2.internal.SynchronizedCaptureSessionBaseImpl.close(SynchronizedCaptureSessionBaseImpl.java:474)
at androidx.camera.camera2.internal.CaptureSession.release(CaptureSession.java:420)
at androidx.camera.camera2.internal.Camera2CameraImpl.releaseSession(Camera2CameraImpl.java:524)
at androidx.camera.camera2.internal.Camera2CameraImpl.resetCaptureSession(Camera2CameraImpl.java:1209)
at androidx.camera.camera2.internal.Camera2CameraImpl.closeCamera(Camera2CameraImpl.java:438)
at androidx.camera.camera2.internal.Camera2CameraImpl$StateCallback.reopenCameraAfterError(Camera2CameraImpl.java:1678)
at androidx.camera.camera2.internal.Camera2CameraImpl$StateCallback.handleErrorOnOpen(Camera2CameraImpl.java:1630)
at androidx.camera.camera2.internal.Camera2CameraImpl$StateCallback.onError(Camera2CameraImpl.java:1606)
at androidx.camera.camera2.internal.CameraDeviceStateCallbacks$ComboDeviceStateCallback.onError(CameraDeviceStateCallbacks.java:121)
at android.hardware.camera2.impl.CameraDeviceImpl.notifyError(CameraDeviceImpl.java:1809)
at android.hardware.camera2.impl.CameraDeviceImpl.$r8$lambda$KBQCqQRdhVVn7uHI9Xdha6OqnsU(Unknown Source:0)
at android.hardware.camera2.impl.CameraDeviceImpl$$ExternalSyntheticLambda0.accept(Unknown Source:8)
at com.android.internal.util.function.pooled.PooledLambdaImpl.doInvoke(PooledLambdaImpl.java:281)
at com.android.internal.util.function.pooled.PooledLambdaImpl.invoke(PooledLambdaImpl.java:204)
at com.android.internal.util.function.pooled.OmniFunction.run(OmniFunction.java:97)
at androidx.camera.core.impl.utils.executor.SequentialExecutor$1.run(SequentialExecutor.java:111)
at androidx.camera.core.impl.utils.executor.SequentialExecutor$QueueWorker.workOnQueue(SequentialExecutor.java:231)
at androidx.camera.core.impl.utils.executor.SequentialExecutor$QueueWorker.run(SequentialExecutor.java:173)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
at java.lang.Thread.run(Thread.java:1012)
But on a real device, takePhoto
succeeds.
ju...@google.com <ju...@google.com> #23
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.camera:camera-core:1.2.0
Description
STACK TRACE:
Fatal Exception: java.lang.NullPointerException: Attempt to invoke interface method 'androidx.camera.core.impl.CameraInfoInternal androidx.camera.core.impl.CameraInternal.getCameraInfoInternal()' on a null object reference
at androidx.camera.core.UseCase.getRelativeRotation(UseCase.java:313)
at androidx.camera.core.ImageCapture.takePicture(ImageCapture.java:978)
at co.hinge.native_video.camera.CameraControllerImpl.takePhoto(CameraControllerImpl.kt:143)
at co.hinge.native_video.camera.CameraControllerImpl.captureListener$lambda-4(CameraControllerImpl.kt:201)
at co.hinge.native_video.camera.CameraControllerImpl.$r8$lambda$Z7Bzo64OXNqGpIXY5QHitLFRIkI(CameraControllerImpl.kt)
at co.hinge.native_video.camera.CameraControllerImpl$$InternalSyntheticLambda$0$23873afc6e7147f4036a3f6c419c8d5a4530ec3f20159b25a8a53d454207f80f$0.accept(CameraControllerImpl.java:4)
at androidx.camera.video.Recorder$RecordingRecord.lambda$updateVideoRecordEvent$6(Recorder.java:2624)
at androidx.camera.video.Recorder$RecordingRecord.$r8$lambda$Uo40MCKPuma4aZ5df1-_fzufzHg(Recorder.java)
at androidx.camera.video.Recorder$RecordingRecord$$InternalSyntheticLambda$1$e783a4176ab49ebfaa1a77688524b1d8bf60886e8cc14f3df37f7a13164ca840$0.run(Recorder.java:4)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:233)
at android.app.ActivityThread.main(ActivityThread.java:8010)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:631)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:978)
CAMERAX VERSION: 1.1.0-beta01 (however we just updated to 1.1.0-beta03, will follow up if crash resolves)
CAMERA APPLICATION NAME AND VERSION: Hinge 8.32.0
ANDROID OS BUILD NUMBER: We are seeing this crash occur on android 5, 6, 7, 8, 9, 10, and 11
DEVICE NAME: This crash is happening on Samsung, Xiaomi, OPPO, and asus phones
DESCRIPTION: This is happening when takePicture() is called on the image capture. Upon investigating the ImageCapture code I believe getCamera() is returning null when we attempt to get the relative rotation on line 978. I'm unsure why that value would be null as it is only nulled out upon binding/releasing use cases. I rebind use cases when I flip the camera. I experimented on taking images while aggressively flipping the camera and was unable to produce a crash.
LIST ANY EXPERIMENTAL FEATURES: We are injecting the ImageCapture and ListenableFuture<ProcessCameraProvider> into the class as opposed to creating them and storing them.
STEPS TO REPRODUCE: I have been unable to reproduce this bug
REPRODUCIBILITY: This crash has occurred 40 times as of the moment I'm filing this bug report.