2016-02-16 133 views
0

看来,最近我的应用程序崩溃,因为renderbufferStorage方法返回false。我不知道会发生什么,所以我之前已经添加了测试,但他们从未提出异常。我在主线程,目前情况下似乎罚款,该eaglLayer过,但无论如何,它崩溃的renderbufferStorage ..OpenGL ES 2.0 renderbufferStorage崩溃

EAGLContext* defaultEAGLContext = getDefaultContext(); 
EAGLContext* currentContext = [EAGLContext currentContext]; 

if(![NSThread isMainThread]) { 
    NSLog(@"ERROR : renderbufferStorage not called on main thread"); 
    @throw [NSException exceptionWithName:@"ERROR" 
            reason:@"renderbufferStorage not called on main thread" 
           userInfo:nil]; 
} 

if(!currentContext) { 
    @throw [NSException exceptionWithName:@"ERROR" 
            reason:@"Current context is null" 
           userInfo:nil]; 
} 

if(!defaultEAGLContext) { 
    @throw [NSException exceptionWithName:@"ERROR" 
            reason:@"Default context is null" 
           userInfo:nil]; 
} 

if(defaultEAGLContext != currentContext) { 
    @throw [NSException exceptionWithName:@"ERROR" 
            reason:@"Default context is different than current context" 
           userInfo:nil]; 
} 

if(!_eaglLayer) { 
    @throw [NSException exceptionWithName:@"ERROR" 
            reason:@"EAGL layer error" 
           userInfo:nil]; 
} 

if (![defaultEAGLContext renderbufferStorage:GL_RENDERBUFFER fromDrawable:_eaglLayer]) { 
    NSLog(@"ERROR : Failed to obtain renderbuffer storage from layer"); 
    @throw [NSException exceptionWithName:@"ERROR" 
            reason:@"Failed to obtain renderbuffer storage from layer" 
           userInfo:nil]; 
} 

你知道为什么这个方法将返回false,甚至随意?在此先感谢

回答

0

其实我的init()方法被调用了两个由于某些线程时间不同步。因此,“renderbufferStorage”被调用了2次,并且第二次返回false,因为存储已经从图层获取。

0

您应该写什么崩溃说,但最常见的错误是忘记覆盖目标视图的layerClass方法。

视图,其层您在渲染缓冲存储器使用必须具备以下重写:

+ (Class)layerClass { 
    return [CAEAGLLayer class]; 
} 
+0

谢谢你的回答。我已经有了这部分代码,但是:方法只是返回false,不幸的是没有日志。如果渲染缓冲区没有设置,它会崩溃,所以我提出异常之前用crashlytics检索它。它是一个不好主意? 编辑:它也随机崩溃,一些用户得到它,但我从来没有repro它:( – Xys

+0

我明白了,所以该方法不会崩溃,但返回false ...您的渲染缓冲区是否绑定在当时? –

+0

是,建立上下文(并将其设定电流)后,我结合这样的缓冲: glGenRenderbuffers(1,_colorRenderBuffer); glBindRenderbuffer(GL_RENDERBUFFER,_colorRenderBuffer); – Xys