preventing的Andr​​oid GL上下文损失 [英] Preventing Android GL Context loss

查看:236
本文介绍了preventing的Andr​​oid GL上下文损失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

再次提出这个问题,因为我敢肯定,它已经做了死亡已经道歉。 :)

Apologies for raising this issue again as i'm sure its been done to death already. :)

不过,我正在转换一个完全原生的游戏到Android和现在我正在研究处理GL上下文的损失。

However i'm converting a fully native game over to Android and i'm now looking into handling GL context loss.

我们认为包含GL资产我能够通过它们旋转和恢复GL上下文我们的游戏内资源的名单。然而,尽管这部作品在简化测试应用程序我有点担心,因为环境损失可以发生在任何时间,我怀疑我将不得不修改其他游戏领域,(螺纹一开始资源处理),以确保我正在覆盖了。

As we maintain a list of 'resources' within our game that contain the GL assets i'm able to spin through them and restore the GL context. However, though this works in a simplified test application i'm a little concerned that as context loss can occur at any time, i suspect i'll have to modify other game areas, (threaded resource handling for a start), to make sure i'm covering everything.

在我的脑海我不禁觉得preventing发生的背景下损失可能是设备的我需要支持的范围内更安全的选择,(均小于2岁左右),并且使用API8。

At the back of my mind i can't help feeling that preventing the context loss from occurring might be a safer option for the range of devices i need to support, (all less than 2yrs old), and using API8.

截至本第一遍,以确定这是否会实际上是可行的,我只是创建了一个静态的 EGLContext 的在我的扩展的 GLSurfaceView 的类实现和创造的环境进入这一点,(我们的原生Android应用程序是根据各地的HELLO-gl2jni例如在Android NDK):

As a first pass at this to determine if this would was actually viable on the i simply created a static EGLContext in my extended GLSurfaceView class implementation and created the context into this, (our native Android applications are based around the hello-gl2jni example in the android ndk):

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;
}

我后来干脆删除了破坏环境的呼叫:

I then simply removed the destroy context call:

public void destroyContext(EGL10 egl, EGLDisplay display, EGLContext context) {
  //egl.eglDestroyContext(display, context);
}

然后在申请再入境,通过pressing首页然后选择从最近的应用列表按钮,该应用程序,该应用程序崩溃。下面是跟踪日志:

Then on application re-entry, through pressing Home then selecting the application from the Recent Apps List button, the application crashed. Here is the trace log:

// 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)

我在崩溃有点惊讶,虽然我认为它强调,我不完全了解这里的过程。

I was a little surprised at the crash though i think it highlights that i don't fully understand the process here.

有谁现在怎么我可以修改我的 GLSurfaceView 的类实现以prevent GL上下文的损失,并能不崩溃,所以我可以测试成功地重新进入应用程序这个选项是值得下面?

Does anyone now how i can modify my GLSurfaceView class implementation to prevent GL context loss and be able to successfully re-enter the application without crashing so i can test is this option is worth following?

我应该说,我试图做这我自己,如果我的工作如何做,我会后回答。 :)

I should say that i'm attempting to do this myself so i'll post the answer if i work out how to do it. :)

非常感谢,

安迪·斯莱​​特

推荐答案

在Android上,你不应该强行留住GL上下文。在移动设备,根据设备capabitilies,这是正常的,你的应用程序被要求或预期释放的背景下(后来将它找回来)。

On Android, you shouldn't forcefully retain the GL context. On mobile devices, depending on the device capabitilies, it is normal that your application is asked or expected to release the context (and later it will get it back).

而不是将其保留,你应该重新加载游戏资源时,GL上下文再次可用。一个好地方,做到这一点是<一个href=\"http://developer.android.com/reference/android/opengl/GLSurfaceView.Renderer.html#onSurfaceCreated%28javax.microedition.khronos.opengles.GL10,%20javax.microedition.khronos.egl.EGLConfig%29\"相对=nofollow> Renderer.onSurfaceCreated 事件。这种方法是由GL渲染线程每当创建或重新创建上下文叫(即,当你previously失去上下文返还给你)。

Instead of retaining it, you should reload your game resources when the GL context is available again. A good place to do this is the Renderer.onSurfaceCreated event. This method is called by the GL renderer thread whenever your context is created or recreated (i.e. when your previously lost context is given back to you).

所以你不必担心GL上下文丢失,你不会知道它:当上下文恢复,onSurfaceCreated总是会叫,你可以肯定这个

So you don't need to worry that the GL context is lost and you won't know about it: when the context is regained, onSurfaceCreated will ALWAYS be called, you can be sure about this.

在一个侧面说明,在Android应用程序,你应该暂停GLSurfaceView在Activity.onPause(),并在Activity.onResume恢复它()。这些可以通过GLSurfaceView.onPause()和onResume()来实现。

On a side note, in an Android application, you should pause your GLSurfaceView in your Activity.onPause(), and resume it in your Activity.onResume(). These can be accomplished via GLSurfaceView.onPause() and onResume().

这篇关于preventing的Andr​​oid GL上下文损失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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