How to fix OpenGL ES application crashes when moving to the background

来源:互联网 发布:java实现转盘抽奖系统 编辑:程序博客网 时间:2024/04/27 23:33

对于iOS应用 OpenGL的渲染如在在应用进入后台后仍在渲染 则APP会crash


iOS apple 官方文档


Background Apps May Not Execute Commands on the Graphics Hardware

An OpenGL ES app is terminated if it attempts to execute OpenGL ES commands on the graphics hardware. iOS prevents background apps from accessing the graphics processor so that the frontmost app is always able to present a great experience to the user. Your app can be terminated not only if it makes OpenGL ES calls while in the background but also if previously submitted commands are flushed to the GPU while in the background. Your app must ensure that all previously submitted commands have finished executing before moving into the background.

If you use a GLKit view and view controller, and only submit OpenGL ES commands during your drawing method, your app automatically behaves correctly when it moves to the background. The GLKViewController class, by default, pauses its animation timer when your app becomes inactive, ensuring that your drawing method is not called.

If you do not use GLKit views or view controllers or if you submit OpenGL ES commands outside a GLKView drawing method, you must take the following steps to ensure that your app is not terminated in the background:

  1. In your app delegate’s applicationWillResignActive: method, your app should stop its animation timer (if any), place itself into a known good state, and then call the glFinish function.

  2. In your app delegate’s applicationDidEnterBackground: method, your app may want to delete some of its OpenGL ES objects to make memory and resources available to the foreground app. Call the glFinish function to ensure that the resources are removed immediately.

  3. After your app exits its applicationDidEnterBackground: method, it must not make any new OpenGL ES calls. If it makes an OpenGL ES call, it is terminated by iOS.

  4. In your app’s applicationWillEnterForeground: method, re-create any objects and restart your animation timer.

To summarize, your app needs to call the glFinish function to ensure that all previously submitted commands are drained from the command buffer and are executed by OpenGL ES. After it moves into the background, you must avoid all use of OpenGL ES until it moves back into the foreground.




Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libGPUSupportMercury.dylib    0x30570094 gpus_ReturnNotPermittedKillClient + 0
1   libGPUSupportMercury.dylib    0x305700ae gpus_KillClient ( )
2   libGPUSupportMercury.dylib    0x305705ba gpusSubmitDMABuffers ( )
3   IMGSGX535GLDriver             0x34bd29b8 SubmitPacketsIfAny ( )
4   IMGSGX535GLDriver             0x34bd2ad0 glrFlushContextToken ( )
5   GLEngine                      0x37719c4a gliPresentViewES ( )
6   OpenGLES                      0x323df6b4 -[EAGLContext presentRenderbuffer:] ( )
...
...

可以参看此文档 https://developer.apple.com/library/content/documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/ImplementingaMultitasking-awareOpenGLESApplication/ImplementingaMultitasking-awareOpenGLESApplication.html#//apple_ref/doc/uid/TP40008793-CH5-SW1

但是并没有给出解决办法 还是在进入后台时停止所有的OpenGL渲染吧。

参考:https://developer.apple.com/library/content/qa/qa1766/_index.html

阅读全文
0 0
原创粉丝点击