输入前景背景时,iOS OpenGL / GPUImage崩溃

时间:2014-01-25 08:26:18

标签: ios opengl-es gpuimage

我们正在使用iOS OpenGL / GPUImage预览屏幕中的某些类型的applicationDidBecomeActive和DidEnterBackground发生崩溃。具体来说,只有在按下/释放电源按钮以使应用程序背景时才会发生。如果单击主页按钮并将应用程序发送到后台并重新激活,则不会发生这种情况。我们没有在后台调用任何OpenGL [已阅读Apple DO和DONT] - 应用程序在BG中没有做任何事情并试图在DidResign本身停止。

只有当设备传感器有一个新的视频捕获帧时才会进行GPU调用,我认为当它进入后台时,它会被iOS暂停。因此,下面的堆栈跟踪只能在应用程序重新启动时或在正式暂停之前触发???

当应用程序进入bg并重新激活时,是否有人知道需要遵循的任何Apple或其他iOS / OpenGL分配/发布协议?更重要的是,是否有一种干净的方法来清除/释放所有OpenGL / GPUImage帧缓冲区/纹理/上下文等,并重新初始化所有内容?


部分堆栈跟踪如下所示,它与EXC_BAD_ACCESS崩溃:

#6  0x003635fe in -[GPUImageContext presentBufferForDisplay] at 
#7  0x0035c416 in -[GPUImageView presentFramebuffer] at 
#8  0x0035cb4a in __44-[GPUImageView newFrameReadyAtTime:atIndex:]_block_invoke at 
#9  0x00363d9e in runSynchronouslyOnVideoProcessingQueue at 
#10 0x0035c89e in -[GPUImageView newFrameReadyAtTime:atIndex:] at 
#11 0x00357a12 in -[GPUImageFilter informTargetsAboutNewFrameAtTime:] at 

2 个答案:

答案 0 :(得分:1)

不确定我是否遇到了同样的问题,但是当应用程序放在后台时,我确实收到EXC_BAD_ACCESS错误。

当应用程序进入后台时,我可以通过暂停(并恢复)视频预览来解决此问题。

绑定应用程序,以便在GPUImageVideoCamera startCameraCapture之后通知您后台/前台活动:

- (void)addObservers {
    [[NSNotificationCenter defaultCenter]addObserver:self
                                            selector:@selector(applicationDidEnterBackground:)
                                                name:UIApplicationDidEnterBackgroundNotification
                                              object:nil];

    [[NSNotificationCenter defaultCenter]addObserver:self
                                            selector:@selector(applicationDidBecomeActive:)
                                                name:UIApplicationDidBecomeActiveNotification
                                              object:nil];
}

使用GPUImageVideoCamera stopCameraCapture并使用dealloc方法停止相机后添加这些内容:

- (void)removeObservers {
    [[NSNotificationCenter defaultCenter]removeObserver:self
                                                   name:UIApplicationDidEnterBackgroundNotification
                                                 object:nil];

    [[NSNotificationCenter defaultCenter]removeObserver:self
                                                   name:UIApplicationDidBecomeActiveNotification
                                                 object:nil];
}

并使用这些回调进行状态更改(我不确定这些方法名称是否存在任何名称空间冲突,尽管我还没有):

- (void)applicationDidBecomeActive:(NSNotification *)notification {
    [self.videoCamera resumeCameraCapture];
}

- (void)applicationDidEnterBackground:(NSNotification *)notification {
    // TODO: Stop recording if recording in progress
    [self.videoCamera pauseCameraCapture];
}

答案 1 :(得分:0)

我在照片处理应用程序中遇到类似的问题,它使用开放式着色器来完成它。

可能是在进入后台并返回时,OpenGL着色器程序不再存在。

返回时假设需要重新编译着色器程序。查看gpuimage示例,我不确定是否有一种简单的方法可以告诉每个着色器程序不再编译。

您可能希望将其报告为Brad Larson's github上的错误。或者您可以尝试返回前景销毁并重建所有目标/过滤器。

我现在也看到这个问题已经有几个月了,你现在可能已经找到了解决方案。如果您能够回答自己的问题以帮助SO社区,那就太好了。

相关问题