除了正确处理:" getParameters失败(空参数)"正确处理、参数、QUOT、getParameters

2023-09-13 00:22:36 作者:一只小肥羊

我在谷歌的摄像机应用Play商店安装了谷歌Analytics(分析)。我不断收到以下崩溃报告:

I have a camera app in the Google Play store with Google Analytics installed. I keep getting the following crash report:

getParameters失败(空参数)

getParameters failed (empty parameters)

我的问题是:?什么是正确的方式来处理这个

展望了它发生在哪里没有给我任何多余的细节的Andr​​oid源。该错误是扔在android_hardware_Camera.cpp:

Looking into the Android source of where it happens didn't give me any extra details. The error is thrown in android_hardware_Camera.cpp:

String8 params8 = camera->getParameters();
if (params8.isEmpty()) {
    jniThrowRuntimeException(env, "getParameters failed (empty parameters)");
    return 0;
}

展望开源的Andr​​oid摄像头,看看它是如何处理的情况也并不十分有益。这code不会出现在调用getParameters时赶上RuntimeException的。 (除了在一种情况下,他们抓住它,关闭相机,然后重新抛出)。

Looking into open source Android camera to see how it handles the situation was also not very helpful. That code doesn't appear to catch the RuntimeException when calling getParameters. (Except in one case where they catch it, close the camera, then rethrow it).

有没有一种正确的方式来处理呢?

如果不是,是否有一个原因,这种情况常常?

请注意: 在任何一天我的5K - 8K活跃用户。这些异常的40-70之间的某处。这似乎的真正的高我。我知道有合法的情况下相机可能无法初始化。但1%的用户似乎不合理。此外,由于Android摄像头应用程序不处理异常它真的让我不知道是否有其他的一些根本原因。

Note: On any given day I have between 5k - 8k active users. With somewhere between 40-70 of these exceptions. That seems really high to me. I know there are legit instances where a camera may fail to initialize. But 1% of users seems unreasonable. Also, since the Android camera app doesn't handle the exception it really makes me wonder if there is some other root cause.

推荐答案

由于+埃迪Talvala提到的,这发生在相机是在一个糟糕的状态

As +Eddy Talvala mentioned, this happens when the camera is in a bad state.

如何相机得到一个糟糕的状态?

1)可能是最常见的原因将被关闭/释放的相机,而仍然使用它之后。这可能是特别有问题的,如果你使用的是在多线程的Camera对象不同步访问摄像头。请确保您永远只能有在同一时间访问摄像机的单个线程。

1) Probably the most common reason would be closing/releasing the camera while still using it afterward. This can be especially problematic if you are using the Camera object on multiple threads without synchronizing access to the Camera. Make sure you only ever have a single thread accessing the Camera at a time.

2)对我来说,这是一个有点比较麻烦。我使用的表面纹理,这样我可以用相机输出作为一个OpenGL纹理。在安卓4.0(ICS),有一个新的方法SurfaceTexture.release()。使用SurfaceTextures时,它清除了内存速度比它previously没有使用这种方法是很重要的。

2) In my case it was a bit more tricky. I use a SurfaceTexture so that I can use the camera output as an OpenGL texture. In Android 4.0 (ICS), there is a new method SurfaceTexture.release(). This method is important to use when using SurfaceTextures as it cleans up the memory quicker than it previously did.

现在的问题是,我在呼唤SurfaceTexture.release(),而摄像头preVIEW依然活跃。这是崩溃相机业务,这是造成问题的问题解释说。

The problem is that I was calling SurfaceTexture.release() while the camera preview was still active. This was crashing the Camera service, which was caused the issue explained in the question.

在我来说,我通过延迟调用SurfaceTexture.release(),直到我曾与一个新的更换表面纹理后,固定它。这样,我是一定的表面纹理,可以清理无任何不良的副作用。

In my case I fixed it by delaying the call to SurfaceTexture.release() until after I had replaced it with a new SurfaceTexture. This way I was certain the SurfaceTexture could be cleaned up without any bad side-effects.