GLSurfaceView EGL_BAD_ALLOC
我的程序在两个 Activity
之间切换,每个 Activity 都会膨胀一个使用 VBO 的派生 GLSurfaceView
。
在两个 Activity 之间来回切换几次后,程序崩溃并抛出以下异常:
Java.lang.RuntimeException: createContext failed: EGL_BAD_ALLOC
at android.opengl.GLSurfaceView$EglHelper
.throwEglException(GLSurfaceView.java:1079)
at android.opengl.GLSurfaceView$EglHelper
.throwEglException(GLSurfaceView.java:1071)
at android.opengl.GLSurfaceView$EglHelper
.start(GLSurfaceView.java:927)
at android.opengl.GLSurfaceView$GLThread
.guardedRun(GLSurfaceView.java:1248)
at android.opengl.GLSurfaceView$GLThread
.run(GLSurfaceView.java:1118)
每次进行上下文切换时,VBO 缓冲区都会被删除,调用 onStop() 并调用下一个 Activity 的新实例 < code>GLSurfaceView 已膨胀。
我重构了程序,使其仅在一个 GLSurfaceView
和 Activity
上运行,并且该程序似乎运行顺利。
仅使用多边形和颜色,不使用纹理。
通过一些互联网研究,这是一个已识别的错误。那么如何进行损害控制呢?
编辑:我解决了问题(我忘记在视图上调用 ONPAUSE() / ONRESTART() )。
My program switches between two Activities
that each inflate a derived GLSurfaceView
that uses VBOs.
After switching back and forth between the two Activities a few times, the program crashes and throws the following exception:
Java.lang.RuntimeException: createContext failed: EGL_BAD_ALLOC
at android.opengl.GLSurfaceView$EglHelper
.throwEglException(GLSurfaceView.java:1079)
at android.opengl.GLSurfaceView$EglHelper
.throwEglException(GLSurfaceView.java:1071)
at android.opengl.GLSurfaceView$EglHelper
.start(GLSurfaceView.java:927)
at android.opengl.GLSurfaceView$GLThread
.guardedRun(GLSurfaceView.java:1248)
at android.opengl.GLSurfaceView$GLThread
.run(GLSurfaceView.java:1118)
Each time there is a context switch the VBO buffers are deleted, onStop() is called, and a new instance of the next Activity's GLSurfaceView
is inflated.
I refactored the program to run on only one GLSurfaceView
and Activity
, and the program seems to run without incident.
Only polygons and colors are used, no textures.
From doing some internet research, this is a recognized bug. So how do I do damage control?
EDIT: I SOLVED THE PROBLEM (I FORGOT TO CALL ONPAUSE() / ONRESTART() ON THE VIEWS).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
令人烦恼的是,我还不能发表评论,但我认为你的意思是 onResume,而不是 onRestart。您的 Activity 可以在不停止的情况下暂停,这会导致 onPause,但不会导致 onRestart。
此图片(来自 Activity 文档)很好地展示了此 Activity 生命周期:
总之,记得将 onPause 和 onResume 传递给都是你的超级并到 GLSurfaceView。
来自 http://android-developers.blogspot.com/2009/04/介绍-glsurfaceview.html:
Annoyingly I can't post a comment yet, but I think you mean onResume, not onRestart. Your Activity can be paused without being stopped, which would cause onPause, but not onRestart.
This image (from the Activity docs) shows this activity life cycle very nicely:
In short, remember to pass onPause and onResume to both your super and to the GLSurfaceView.
From http://android-developers.blogspot.com/2009/04/introducing-glsurfaceview.html: