iOS 在背景初始化 mapview 會導致crash

平常開發上面我們知道不能在背景使用openGL,否則app會直接crash給你看。像是這篇Technical Q&A QA1766提到要特別注意當app切換到背景時,要確保沒有再處理相關openGL的訊息。

而這次比較特別是在收到memory warnning後,viewController又重新去init一個mapview,因為mapview會使用到openGL而導致crash,最後你會收到類似這樣的crash log:

0   libGPUSupportMercury.dylib     0x334e98a6 gpus_ReturnNotPermittedKillClient + 10
1   libGPUSupportMercury.dylib     0x334ea360 gpusSubmitDataBuffers + 108
2   libGPUSupportMercury.dylib     0x334ea1e0 gldCreateContext + 204
3   GLEngine                         0x2f15e536 gliCreateContextWithShared + 598
4   OpenGLES                         0x2f23aab0 -[EAGLContext initWithAPI:properties:] + 404
5   OpenGLES                         0x2f23a8fa -[EAGLContext initWithAPI:sharegroup:] + 110
6   VectorKit                        0x377d003e ggl::OESContext::OESContext(ggl::GLDevice*, std::__1::shared_ptr<ggl::OESSharegroup>) + 486
7   VectorKit                        0x377c9160 ggl::GLDevice::createRenderer() + 88
8   VectorKit                        0x376e8ce4 -[MDDisplayLayer _createGLLayer] + 164
9   VectorKit                        0x376e8a82 -[MDDisplayLayer init] + 66
10  VectorKit                        0x3741b3ca -[VKMapView initWithGlobe:shouldRasterize:inBackground:] + 482
11  MapKit                           0x2df578dc -[MKBasicMapView initWithFrame:andGlobe:shouldRasterize:] + 356
12  MapKit                           0x2df89b24 -[MKMapView _commonInitFromIB:gestureRecognizerHostView:showsAttribution:] + 968
13  MapKit                           0x2df75c76 -[MKMapView initWithFrame:] + 126

以後還是要多注意一下背景狀態下的memory warning,而且發現使用模擬器是重置不出來的,如果要在實機測試memory warning 可以使用private method:

[[UIApplication sharedApplication] performSelector:@selector(_performMemoryWarning)];

reference:

http://stackoverflow.com/questions/12713781/occasionally-ios-6-mkmapview-crashes-in-initwithframe

comments powered by Disqus