抱歉再次提出这个问题,因为我确信这个问题已经死了。 ) :
然而,我将一个完全本地的游戏转换成 Android, Im, 研究如何处理GL上下文损失。
当我们在游戏中保留一个资源列表, 包含 GL 资产, im 能够翻转并恢复 GL 上下文。 然而, 虽然这在简化测试应用程序中有效, i m 有点担心当背景损失随时可能发生时, 我怀疑我必须修改其它游戏区域, ( 开始处理线索资源) 才能确保i m 覆盖一切 。
在我脑海的背面,我忍不住觉得,防止背景损失的发生,对于我需要支持的各种装置(都不到2岁)和使用API8,可能是更安全的选择。
首先确定这是否真的可行, 仅凭我扩展的“GLSurfaceView , 并由此创建了上下文, (我们本地的Android应用程序以Hello-gl2jni 例为基础,
public EGLContext createContext(EGL10 egl, EGLDisplay display, EGLConfig eglConfig) {
if (mEGLContext == null)
{
...
mEGLContext = egl.eglCreateContext(display, eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list);
}
return mEGLContext;
}
然后我简单地删除了毁灭背景的呼唤:
public void destroyContext(EGL10 egl, EGLDisplay display, EGLContext context) {
//egl.eglDestroyContext(display, context);
}
然后在应用程序再返回时,通过按住 Home,然后从最近的 Apps List 按钮中选择应用程序,程序就崩溃了。 这是跟踪日志 :
// home button pressed
05-23 17:04:26.784: W/GlContextTrace(11504): Activity State Change: onPause (pausing)
05-23 17:04:26.808: W/GlContextTrace(11504): GLSurfaceView.EGLContextFactory::destroyContext (doesn t actually call eglDestroyContext)
05-23 17:04:27.519: W/GlContextTrace(11504): Activity State Change: onStop
// application re-entry
05-23 17:04:30.089: W/GlContextTrace(11504): Activity State Change: onRestart
05-23 17:04:30.089: W/GlContextTrace(11504): Activity State Change: onStart
05-23 17:04:30.089: W/GlContextTrace(11504): Activity State Change: onResume
05-23 17:04:30.229: W/GlContextTrace(11504): GLSurfaceView.EGLContextFactory::createContext (uses the previously created GL context)
// which immediately invokes destroyContext and ends my application:
05-23 17:04:30.315: W/GlContextTrace(11504): GLSurfaceView.EGLContextFactory::destroyContext
05-23 17:04:30.479: W/GlContextTrace(11504): Activity State Change: onPause
05-23 17:04:30.636: W/GlContextTrace(11504): Activity State Change: onStop
05-23 17:04:30.636: W/GlContextTrace(11504): Activity State Change: onDestroy
坠机日志是:
05-23 17:04:30.401: W/dalvikvm(11504): threadid=11: thread exiting with uncaught exception (group=0x40a361f8)
05-23 17:04:30.409: E/AndroidRuntime(11504): FATAL EXCEPTION: GLThread 753
05-23 17:04:30.409: E/AndroidRuntime(11504): java.lang.RuntimeException: eglMakeCurrent failed: EGL_SUCCESS
05-23 17:04:30.409: E/AndroidRuntime(11504): at android.opengl.GLSurfaceView$EglHelper.throwEglException(GLSurfaceView.java:1178)
05-23 17:04:30.409: E/AndroidRuntime(11504): at android.opengl.GLSurfaceView$EglHelper.throwEglException(GLSurfaceView.java:1170)
05-23 17:04:30.409: E/AndroidRuntime(11504): at android.opengl.GLSurfaceView$EglHelper.createSurface(GLSurfaceView.java:1081)
05-23 17:04:30.409: E/AndroidRuntime(11504): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1433)
05-23 17:04:30.409: E/AndroidRuntime(11504): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1216)
我对这次坠机感到有点惊讶,
现在有谁能让我如何修改我的 GLSurfaceView 类功能, 以防止 GL 上下文损失, 并能够成功重新进入应用程序而不崩溃, 这样我就可以测试这个选项是否值得遵循?
我应该说,我试图自己做这件事,所以如果我想如何做,我会公布答案。 )
非常感谢,
安迪·斯莱特