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

对于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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值