5

My application is an OpenGL heavily employed one, which is being used to process images, rendering scenes, display previews, etc. However, after I implemented multi-task as Apple's official document 'OpenGL ES Programming Guide for iOS', weird crashes still came up sporadically. Debug Navigator Stack trace shows something like 'sgxPatchDeferredFramebufferOffsets', 'presentRenderbuffer EXC_BAD_ACCESS', 'gpus_ReturnNotPermittedKillClient', etc.

So, I would like to know what exactly one should implement OpenGL ES Multi-task.

=============UPDATE: Problem Solved============

Thanks for your answer, CStreel, and other guys who tried to help.

After reading 'Background Applications May Not Execute Commands on the Graphics Hardware' part in'OpenGL ES Programming Guide for iOS' a second time, line by line, I have a new understanding with this issue.

The big problem with my app is I should not implement OpenGL ES multi-task in a notification method. Since, unlike delegate methods, notification methods will be called asynchronously, these stopping animation actions and glFinish() calls may not take effect when the application has already moved into the background. This may happen more frequently when I hit the lock-screen button as soon as I am performing a series of OpenGL ES related actions.

If you guys found some other issues, feel free to contact me.

4

2 回答 2

4

当您的应用程序即将进入后台时,如果您的应用程序调用任何 OGLES 函数,操作系统将立即终止您的应用程序

阅读应用程序状态和多任务处理以获取更多信息 阅读成为负责任的后台应用程序

以下是该文档的一些摘录:

(Required) When moving to the background, make sure your app adjusts its behavior appropriately.

关于 OGLES

 ...the app should stop calling OpenGL ES functions.
于 2012-10-17T03:18:53.823 回答
0

通知可以是同步的或异步的。如果注册通知指定 NSOperationQueue,回调将是异步的,否则我相信它总是同步的。

我遇到了一些崩溃,并在我的代码中发现了一些错误:

  1. 共享的 EAGLContext,尽管是“多线程的”,但并不总是在所有使用它的线程上设置。似乎每次离开 RunLoop 以输入您的应用程序代码并发出任何 openGL 命令时,您都必须在主线程上设置上下文。
  2. iOS 6 在更改缓冲区时需要额外的“glFlush()”,这显然是由于 iOS 6 中的一个错误。iOS 5 和 7 不受影响。
  3. “DidEnterBackground”通知与其他代码/线程之间缺乏同步,这意味着通知应用程序状态更改的主线程提前返回,而其他线程仍在使用 openGL。保持通知线程,直到您完成调用 openGL。只有在允许返回后,iOS 才会在 openGL 上启动“看门狗”。

我使用 DidEnterBackground/WillEnterForeground 通知(不是回调)来停止/重新启动 openGL 操作。我仍然遇到非常罕见的崩溃(我必须使用自动化并锁定/解锁/旋转 20-30 分钟才能得到它),但使用 WillResignActive/DidBecomeActive 没有任何区别;他们无论如何都会发生。

于 2014-03-17T11:57:52.857 回答