Camera.start preVIEW崩溃和活动的多次运行后重新启动手机 [英] Camera.startPreview crashes and reboots phone after multiple runs of Activity

查看:1014
本文介绍了Camera.start preVIEW崩溃和活动的多次运行后重新启动手机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个活动在打开的摄像机并启动preVIEW在表面纹理。一切工作正常,但我发现,如果我多次离开活动并返回到它,少数时间后,手机死机,然后重新启动。

I have an Activity that opens the Camera and starts a preview on a SurfaceTexture. Everything works fine, but I've noticed that if I repeatedly leave the activity and return to it, after a handful of times, the phone freezes and then reboots.

我已经缩小的问题倒在调用start preVIEW。而我得到两个不祥的日志信息的问题发生权利之前:

I've narrowed the problem down to the call to startPreview. And I get two ominous log messages right before the issue happens:

01-19 10:20:52.038: E/IMGSRV(22777): :0: __map: Map device memory failed
01-19 10:20:52.038: W/GraphicBufferMapper(22777): registerBuffer(0x70b750) failed -14 (Bad address)

有没有人见过这个?这是一个问题与Galaxy Nexus的硬件还是Android 4.0?如果是这样,是否有任何变通?

Has anyone seen this before? Is this an issue with the Galaxy Nexus hardware or Android 4.0? If so, are there any work arounds?

注:我的测试是在Android 4.0,与Galaxy Nexus的

Note: My testing is on Android 4.0, with a Galaxy Nexus.

修改 - 解决:

原来这是由于OpenGL的内存泄漏。所有在网络上的例子我能找到使用下面的code后的OpenGL清理。

Turns out it was a memory leak due to OpenGL. All the examples on the web I could find use the following code to clean up after OpenGL.

try { mEgl.eglDestroyContext(mEglDisplay, mEglContext); } catch (Throwable t) {}
try { mEgl.eglDestroySurface(mEglDisplay, mEglSurface); } catch (Throwable t) {}

这漏面,并作为一定数量的尝试,其中每部手机变化后的结果,会导致OpenGL的失败初始化。比如,它会经过32次尝试了Nexus S上,但只有8次尝试在LG擎天柱失败。

This leaks the surface, and as a result after some number of tries, which varies per phone, will cause OpenGL to fail to initialize. For instance it would fail after 32 tries on the Nexus S, but only 8 tries on the LG Optimus.

在一些试验和错误,我发现下面的code固定的问题:

After some trial and error I found that the following code fixed the issue:

mEgl.eglMakeCurrent(mEglDisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);

注:在Galaxy Nexus的,而不是得到一个不错的OpenGL错误,我可以显示它只是似乎崩溃的开始preVIEW用户。我认为这是与内存相关,但上面固定清零好了。

Note: On the Galaxy Nexus instead of getting a nice OpenGL error which I could display to the user it just seemed to crash on startPreview. I assume this was memory related, but the above fixed cleared it up as well.

推荐答案

SDK文档的android.hardware.Camera类说以下内容:

重要提示:呼叫发布()释放摄像头,以供其他用途   应用程序。应用程序应该立即松开相机   的onPause()(和再 - 的open() onResume())。

Important: Call release() to release the camera for use by other applications. Applications should release the camera immediately in onPause() (and re-open() it in onResume()).

您一定的活性释放相机的onPause() onResume重新打开它()

Are you certain your activity releases the camera in onPause() and re-opens it in onResume()?

如果您发布一个code样品,我们将能够更好地解决您的问题。

If you post a code sample, we would be better able to troubleshoot your problem.

这篇关于Camera.start preVIEW崩溃和活动的多次运行后重新启动手机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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