Correct handling of exception: “getParameters failed (empty parameters)”

前端 未结 4 447
小蘑菇
小蘑菇 2020-12-03 00:34

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

getParameters failed (empty

4条回答
  •  余生分开走
    2020-12-03 01:12

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

    How does the camera get in a bad state?

    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) 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.

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

    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.

提交回复
热议问题