当一些代码在后台线程上运行时,我正在尝试更新和加载 UIProgressBar。当后台线程完成加载创建头像时,它应该将变量 avatarFinishedLoading 更新为 TRUE,这使得 Open GL ES 更新方法中的代码开始运行。
- (void)viewDidAppear:(BOOL)animated
{
[self performSelectorOnMainThread:@selector(updateProgressBar) withObject:nil waitUntilDone:NO];
dispatch_queue_t loadAvatarAndFrames = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(loadAvatarAndFrames, ^{
[self createAvatar];
dispatch_async(dispatch_get_main_queue(), ^{
avatarFinishedLoading = TRUE;
});
});
}
- (void)updateProgressBar {
float progress = [threadProgressView progress];
if (progress < 1) {
threadProgressView.progress = progress + (float)0.01;
[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(updateProgressBar) userInfo:nil repeats:NO];
}else{
[threadProgressView setHidden:TRUE];
}
}
- (void)update
{
// Set colour of background
glClearColor(self.backgroundColour.x, self.backgroundColour.y, self.backgroundColour.z, self.backgroundColour.w);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
if (avatarFinishedLoading == TRUE){
//Do Some Code
}
}
应用程序崩溃并显示错误消息:0xf5a2503: movzwl (%eax,%ecx,2), %eax exec_bad_access
我无法弄清楚我哪里出错了,因为这对我来说似乎没问题。
编辑
在后台线程上执行此代码时,我似乎遇到了 GL 错误:1280。如果我在主线程上运行“createAvatar”方法,我不会收到任何 GL 错误,并且头像按预期呈现
谢谢