项目中使用GPUImage自定义相机录制短视频,测试发现锁屏后再进入App会Crash,每次都崩溃在以下代码:
- (void)presentBufferForDisplay;
{
[self.context presentRenderbuffer:GL_RENDERBUFFER];
}
在 GPUImage的Issues#197找到了答案,大概原因是iOS不支持后台进行OpenGL渲染,所以切后台之前要调用glfinish()
,将缓冲区中的指令(无论是否为满)立刻送给图形硬件执行,glfinish()
会等待图形硬件执行完才返回。
- (void)observeGlobalNotifications
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onApplicationWillResignActive) name:UIApplicationWillResignActiveNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onApplicationDidBecomeActive) name:UIApplicationDidBecomeActiveNotification object:nil];
}
- (void)unobserveGlobalNotifications
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillResignActiveNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];
}
- (void)onApplicationWillResignActive
{
//[self.camera pauseCameraCapture];
[self.camera stopCameraCapture];
runSynchronouslyOnVideoProcessingQueue(^{
glFinish();
});
}
- (void)onApplicationDidBecomeActive
{
// [self.camera resumeCameraCapture];
[self.camera startCameraCapture];
}
网友评论