English 中文(简体)
A. 防止人造GL
原标题:Preventing Android GL Context loss

抱歉再次提出这个问题,因为我确信这个问题已经死了。 ) :

然而,我将一个完全本地的游戏转换成 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 上下文损失, 并能够成功重新进入应用程序而不崩溃, 这样我就可以测试这个选项是否值得遵循?

我应该说,我试图自己做这件事,所以如果我想如何做,我会公布答案。 )

非常感谢,

安迪·斯莱特

问题回答

Android, 您应该强制保留 GL 上下文 。 在移动设备上, 取决于设备控制塔, 您的应用程序通常会被要求或预期释放上下文( 稍后它会恢复它 ) 。

当 GL 环境再次可用时, 您应该重新加载您的游戏资源而不保留它。 一个很好的地方就是 < a href=" http:// developmenter.android. com/ reference/android/ opengl/ GLSurfaceView. Render. html# onSurfaceCreated% 28javax. microdition.khronos. hronos. Opengles. GL10,%20javax. microdition.khronos. EGLConfig% 29" rel=" norefer". onSurfaceCreated event。 在您创建或重建上下文时( 即您先前丢失的上下文被反馈给您时), GL 造型线索会调用这种方法 。

所以,你不必担心GL上下文丢失了,你也不会知道:当上下文重新恢复时,在紫色Created号上会叫ALWAYS,你可以肯定这一点。

另提一点, 在 Android 应用程序中, 您应该暂停您的 GLSurfaceView 在活动. onPause () 中, 并在活动. onResume () 中恢复 GLSurfaceView. onPause () 。 这些可以通过 GLSurfaceView. onPause () 和Resume () 完成 。





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签