从iOS 11开始,当我们在GLKView上调用display方法时,我注意到了OpenGL-ES崩溃 . 我们确保正确实例化GLKView和EAGLContext并从适当的线程调用 .

下面是与崩溃相关的堆栈跟踪 .

Exception Type:  SIGABRT
Exception Codes: #0 at 0x182c042e8
Crashed Thread:  0

Thread 0 Crashed:
0   libsystem_kernel.dylib               0x0000000182c042e8 __pthread_kill + 8
1   libsystem_pthread.dylib              0x0000000182d1d748     pthread_kill$VARIANT$armv81 + 356
2   libsystem_c.dylib                    0x0000000182b72fbc abort + 136
3   Metal                                0x0000000184e15a9c MTLReleaseAssertionFailure + 268
4   AppleMetalGLRenderer                 0x00000001a269af18 GLDTextureRec::allocMetalTexture() + 724
5   AppleMetalGLRenderer                 0x00000001a269b010 GLDTextureRec::loadPrivateTexture(unsigned int, unsigned short*) + 52
6   AppleMetalGLRenderer                 0x00000001a269917c GLDTextureRec::update(unsigned int, unsigned short*) + 164
7   AppleMetalGLRenderer                 0x00000001a2695e98 GLDFramebufferRec::load() + 124
8   AppleMetalGLRenderer                 0x00000001a2696224 gldLoadFramebuffer + 12
9   GLEngine                             0x00000001a345e84c gleCheckFramebufferStatus + 112
10  GLEngine                             0x00000001a340bb44 glCheckFramebufferStatusEXT_Exec + 120
11  GLKit                                0x000000018feef330 -[GLKView _createFramebuffer] + 1144
12  GLKit                                0x000000018feef660 -[GLKView _setFramebuffer:] + 128
13  GLKit                                0x000000018feef8ac -[GLKView    _display:] + 84

这是我能够重现崩溃时获得的Xcode控制台输出 .

GTML desc[0] t=4 f=70 w=1001 h=944 d=1 m=1 s=4 a=1 r=1 u=4
failed assertion metalTexture != nil at line 863 in allocMetalTexture

通过堆栈跟踪,看起来崩溃发生在GLKit为GLKView创建帧缓冲区对象时,在它以draw方法调用我们之前 . 我不完全是这个问题的潜在根本原因 .

不幸的是,这次崩溃非常难以重现并且不会持续发生 .

代码中的一些重要代码片段 .

设置GLKView和EAGLContext:

self.eaglContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2 sharegroup:self.resources.shareGroup];

// Create the actual OpenGL view
self.glView = [[GLKView alloc] initWithFrame:self.frame context:self.eaglContext];
self.glView.delegate = self;
self.glView.enableSetNeedsDisplay = NO;
self.glView.contentScaleFactor = self.screenDensity;
self.glView.drawableMultisample = GLKViewDrawableMultisample4X;

[EAGLContext setCurrentContext:self.eaglContext];
//Load custom textures
[EAGLContext setCurrentContext:nil];

//Now, I created vertexArrayObjects using glGenVertexArrays, enable blending etc, setup vertexBufferObjects for vertices and indices using glGenBuffers method.

现在,当我准备好绘制内容时,我正在调用下面的代码 . 我还进行了检查以确保使用eaglContext,GLKView以及创建EAGLContext的相同线程 .

[EAGLContext setCurrentContext:self.eaglContext];
if(!CGRectIsEmpty(self.glView.bounds) && !self.hidden) {
    [self.glView display];
}
[EAGLContext setCurrentContext:nil];

据我所知,我不需要调用bindDrawable,因为我正在使用GLKView提供的默认帧缓冲区本身 .

任何见解/帮助都是真正的赞赏 .