【问题标题】:iOS OpenGL/GPUImage crash when entering background to foregroundiOS OpenGL/GPUImage 在进入后台到前台时崩溃
【发布时间】:2014-02-16 08:56:53
【问题描述】:

只有某些类型的 applicationDidBecomeActive 和 DidEnterBackground 与 iOS OpenGL/GPUImage 预览屏幕发生崩溃。具体来说,只有在按下/释放电源按钮以使应用程序后台运行时才会发生这种情况。如果单击主页按钮并将应用程序发送到后台并重新激活,则不会发生这种情况。我们没有在后台调用任何 OpenGL [已阅读 Apple DO's 和 DONT's] - 应用程序在 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 

【问题讨论】:

  • 升级到更新的 gpuimage,因为这些东西已经改变了 sinde 0.1.10 (12) ...或者你可以修补它..如果你需要快速修复,不要让运行 [self processVideoSampleBuffer:样本缓冲区];在应用程序处于后台时在 GPUImageVideoCamera.m 中,处理队列是异步的,因此停止它们可能不是即时的,新版本的 GPUImage 再次帮助解决这些问题

标签: ios opengl-es gpuimage


【解决方案1】:

我在使用开放式 gl 着色器的照片处理应用程序中遇到了类似的问题。

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

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

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

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

【讨论】:

    【解决方案2】:

    不确定我是否有同样的问题,但在将应用程序置于后台时确实收到了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 stopCameraCapturedealloc 方法停止相机后添加这些:

    - (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];
    }
    

    【讨论】:

    • 请正确缩进
    • 谢谢,没看到。假设您指的是第二个代码块?
    • 在主线程中执行 [self.videoCamera pauseCameraCapture] 仍然有机会让我崩溃,而是在内置的视频进程队列中运行解决问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-09
    • 1970-01-01
    相关资源
    最近更新 更多