CameraX-解除绑定预览UseCase时崩溃 [英] CameraX - crash when unbinding Preview UseCase

查看:840
本文介绍了CameraX-解除绑定预览UseCase时崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户开始拍照时,我需要冻结(停止)预览。我四处搜寻,发现提到取消绑定预览UseCase的帖子。我已经尝试过,起初它可以在Android 9+上正常工作,但是在较低的Android上,我在Logcat中收到以下错误,并且未拍摄图片。

I need to freeze (stop) the preview when user initiates taking the photo. I've searched around and I've found this SO post that mentions unbinding Preview UseCase. I've tried that and at first it works correctly on Android 9+, but on lower Android I receive following error in Logcat and picture is not taken.

ImageCapture: takePictureInternal onFailure

androidx.camera.core.ImageCaptureException: The completer object was garbage collected - this future would otherwise never complete. The tag was: FutureChain[androidx.camera.core.impl.utils.futures.ChainingListenableFuture@3ee79178]
        at androidx.camera.core.ImageCapture$ImageCaptureRequest.lambda$notifyCallbackError$1$ImageCapture$ImageCaptureRequest(ImageCapture.java:1911)
        at androidx.camera.core.-$$Lambda$ImageCapture$ImageCaptureRequest$1G7WSvt8TANxhZtOyewefm68pg4.run(lambda)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5221)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
     Caused by: androidx.concurrent.futures.CallbackToFutureAdapter$FutureGarbageCollectedException: The completer object was garbage collected - this future would otherwise never complete. The tag was: FutureChain[androidx.camera.core.impl.utils.futures.ChainingListenableFuture@3ee79178]

并且也开始出现很多日志,例如

And also a lot of logs starts to appear like

gralloc_ranchu: gralloc_lock usage mismatch usage=0x30 cb->usage=0x3

我的怀疑是我检索 ProcessCameraProvider 实例是错误的-我只是将其存储在从 getInstance 方法返回的Future中,然后再使用它。但是,当我尝试再次获得未来时,它并没有帮助。我没有找到解决方法,我正在考虑将CameraX替换为其他Camera库,因为我花了太多时间在此问题上,但也许有人会回答。

My suspicion is that the way how I retrieve ProcessCameraProvider instance is wrong - I just store it once I get from the Future returned from getInstance method and use it later. But when I tried getting the future again it did not helped. I've found no workaround around this and I am considering replacing CameraX with some other Camera library because I've spent too many time on that but maybe someone has some answer.

我创建了演示项目,我在这里测试了这种奇怪的行为,因此您可以查看完整的代码。

I've created a demo project where I test this weird behavior so you can take a look at the full code.

推荐答案

我已将此错误发布为 Google问题跟踪器,并且此错误是预期的行为。要冻结预览,请勿解除绑定预览用例。将来可能会使用该API,但是目前推荐的方法是存储 ImageAnalysis 中的最新帧,并将其放在与预览重叠的ImageView中。

I've posted this as a bug to Google Issue tracker and this error is intended behavior. To freeze a preview you should not unbind Preview usecase. There may API for that in the future, but currently the recommended way is to store latest frame from ImageAnalysis and put it to ImageView overlapping the preview.

这篇关于CameraX-解除绑定预览UseCase时崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆