2013-07-28 25 views
2

我想添加一個GLKView滾動視圖沒有成功。GLKView給'無法使完整的幀緩衝區對象8cd6'錯誤

此刻,我的繪圖代碼只是簡單地將背景變成紅色,但在它發生之前,它會引發錯誤「無法完成幀緩衝區對象8cd6」錯誤。我已經設法通過將OpenGL繪製成標準的UIView來獲得完全相同的效果,但只要您將它切換爲GLKView,它總是會拋出錯誤。

這裏是我的滾動視圖是如何在AppDelegate.m初始化:

ScrollView *scroll = [[ScrollView alloc] init]; 
[[self window] setRootViewController:scroll]; 

然後在我的ScrollView.m本身有以下幾點:

CGRect screenRect; 

float screenWidth = 1920; 
float screenHeight = 1280; 

UIScrollView *scrollView; 
GLKView *glkView; 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 

    if (self) 
    { 
     // Custom initialization 
    } 

    return self; 
} 

-(void)loadView 
{ 
    // initialise the view's size parameters 
    screenRect.size.width = screenWidth; 
    screenRect.size.height = screenHeight; 

    // init the scrollview with the new screen rect 
    scrollView = [[UIScrollView alloc] initWithFrame:screenRect]; 

    // set the delegate as itself 
    [scrollView setDelegate:self]; 

    // make the scrollview our main view 
    [self setView:scrollView]; 

    // now create the GLKView and context 
    EAGLContext * context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; 
    glkView = [[GLKView alloc] initWithFrame:screenRect]; 
    glkView.context = context; 
    glkView.delegate = self; 

    // add the GLKView to the scrollView 
    [scrollView addSubview:glkView]; 

    /* old code, which works fine */ 
    // OpenGLView openGLView = [[OpenGLView alloc] initWithFrame: screenRect];  
    // openGLView.delegate = self; 
    // openGLView.opaque = NO;  
    // [scrollView addSubview:openGLView]; 
    /* end of old code */ 

    // and finally tell the scrollview the size of it's content 
    [scrollView setContentSize:screenRect.size]; 
} 

- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect 
{ 
    // ** THROWS THE ERROR BEFORE HERE ** // 
    // set the background colour to red 
    glClearColor(1.0, 0.0, 0.0, 1.0); 

    // and now clear it  
    glClear(GL_COLOR_BUFFER_BIT); 
} 

任何理由爲什麼這個代碼將導致這發生?

回答

1

從主線程實例化視圖時發生此錯誤。

FWIW,錯誤消息中的8cd6是GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT的OpenGL錯誤代碼,這意味着OpenGL幀緩衝區沒有完全配置。

+0

英雄。如此明顯,現在我想到了!使用'dispatch_async(dispatch_get_main_queue(),^ {...})'來包裝視圖操作及其固定。 – ComethTheNerd

相關問題