简体   繁体   English

在快速暂停/恢复应用程序时,在Android NDK中使用SurfaceView崩溃

[英]Crash with SurfaceView in Android NDK when pausing/resuming app fast

When I pause/unpause my app really fast then I get the following problem: 当我暂停/取消暂停我的应用程序时,我遇到以下问题:

E/BufferQueueProducer(  177): [SurfaceView] connect(P): already connected (cur=1 req=1)
E/libEGL  (25863): eglCreateWindowSurface: native_window_api_connect (win=0xb4984508) failed (0xffffffea) (already connected to another API?)
E/libEGL  (25863): eglCreateWindowSurface:416 error 3003 (EGL_BAD_ALLOC)

Im pretty sure that I am stopping/starting my render thread correctly and this issue really only occurs when I pause/resume the app really fast (like when you mash the open-apps button). 我很确定我正在停止/正确启动我的渲染线程这个问题真的只发生在我非常快地暂停/恢复应用程序时(比如当你混合打开应用程序按钮时)。

Any ideas what might be the cause for eglCreateWindowSurface returning EGL_NO_SURFACE here? 任何想法可能是eglCreateWindowSurface在这里返回EGL_NO_SURFACE的原因? My guess would be it has to do with something still being connected to the SurfaceView. 我猜这将与仍然连接到SurfaceView的东西有关。

It sounds like you're trying to create an EGLSurface for a Surface that already has one. 听起来你正在尝试为已有的表面创建一个EGLSurface。 If speed is an issue it's usually because of the lag in Surface callback handling -- the SurfaceView Surface is partially handled by the Window Manager, which requires inter-process communication. 如果速度是一个问题,通常是因为Surface回调处理的滞后 - SurfaceView Surface部分由Window Manager处理,这需要进程间通信。

Perhaps your native code still has a handle to the old SurfaceHolder, and if you moved more slowly the handle would be replaced by an upcoming surfaceCreated() ? 也许你的原生代码仍然有旧的SurfaceHolder的句柄,如果你移动得更慢,句柄将被即将到来的surfaceCreated()取代? It's hard to say without knowing exactly what your code does. 如果不确切知道代码的作用,很难说。 One way to approach these sorts of problems is by adding logging at all the interesting state change points, and comparing the logs from "slow" pause/resume and "fast" pause/resume. 解决这些问题的一种方法是在所有有趣的状态变化点添加日志记录,并比较“慢”暂停/恢复和“快速”暂停/恢复的日志。

It should be possible to avoid these situations by managing the SurfaceView state carefully. 应该可以通过仔细管理SurfaceView状态来避免这些情况。 This appendix to the graphics arch doc talks about the difference between the Activity and SurfaceView lifecycles, and two ways to structure an app to avoid issues. 图形arch doc的这个附录讨论了Activity和SurfaceView生命周期之间的区别,以及构建应用程序以避免问题的两种方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM