cicontext drawImage:inRect:fromRect在ios6中崩溃
问题描述:
我试图从相机获取视频并使用CoreImage和OpenGL进行渲染。 当我运行它时,我按照预期在屏幕上看到我的图片,然后获得EXEC_BAD_ACCESS。 我正在使用ARC。 iOS6 Beta1。 请帮我解决它。cicontext drawImage:inRect:fromRect在ios6中崩溃
更新:它在5.1中工作,但在6.0中崩溃。 我提出的所有异常断点,但我只看到EXEC_BAD_ACESS发生在presentRendedBuffer> gpus_ReturnGuiltyForHardwareRestart
UPDATE2:我已经删除相机相关的代码,它仍然崩溃。
更新3:当我注释掉glClearColor & glClear命令我的应用程序停止崩溃。但我仍然想知道如何将OpenGL与Core Image一起使用。
我的新代码那样简单:
@interface MGViewController() {
...
}
@property (strong, nonatomic) EAGLContext *glcontext;
@property (strong, nonatomic) CIContext *cicontext;
@property (strong, nonatomic) CIImage *ciimage;
- (void)viewDidLoad
{
[super viewDidLoad];
self.glcontext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
if (!self.glcontext) {
NSLog(@"Failed to create ES context");
} else {
self.cicontext = [CIContext contextWithEAGLContext:self.glcontext];
if (!self.cicontext){
NSLog(@"Failed to create CI context");
}
}
GLKView *view = (GLKView *)self.view;
view.context = self.glcontext;
view.drawableDepthFormat = GLKViewDrawableDepthFormat24;
self.ciimage = [[CIImage alloc] initWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"roomphoto" withExtension:@"png"]];
}
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
glClearColor(0.0, 0.5, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
[self.cicontext drawImage:self.ciimage
inRect:self.ciimage.extent
fromRect:self.ciimage.extent];
}
此代码适用于iPhone & iPad的6.0模拟器;在iPad2 iOS 6.0 Beta2上与EXEC_BAD_ACCESS崩溃;它给我的iPad 1 & iPhone 4S的的iOS 5.1.1只是绿色画面,在控制台消息:
Invalid shader program, probably due to exceeding hardware resourcesCould not load the kernel!Could not load the kernel! ...
什么可能是错误的?
答
最后,我设法阻止应用程序崩溃。 我刚刚在gl命令和[cicontext drawImage ...]命令之间添加了glFlush()。
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
glClearColor(0.0, 0.5, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
[self.cicontext drawImage:self.ciimage
inRect:self.ciimage.extent
fromRect:self.ciimage.extent];
}
结果并不完美:我可以看到一些抖动等,但至少它的工作原理。 虽然,我将不胜感激详细的答案。
答
drawImage:inRect:fromRect在iOS 6中是异步的。
它会在iOS5.x上崩溃吗? –
不,它适用于我的iPhone 5.1.1,但在6.0版本的iPad上无法使用。 上次我在控制台收到消息: 无法使用GPU渲染,因为在后台进程。 渲染到屏幕时无法回退到CPU - 渲染可能失败! (lldb) 它可能是由于drawImage:inRect:fromRect在iOS6中是异步的,但在iOS5中同步? – Seify
命中命令+6。点击左下角的小加号按钮。选择“添加异常断点”。点击完成。再次运行应用程序。你会看到异常的确切位置。在此报告以获得更好的反馈。 –