We are getting a crash that happens with only certain types of applicationDidBecomeActive and DidEnterBackground with iOS OpenGL/GPUImage preview screen. Specifically, it happens only if the power button is pressed/released to background the app. It doesn't happen if the home button is clicked and app sent to background and reactivated. We are not calling into any OpenGL in the background [have read the Apple DO's and DONT's] - app doesn't do anything in the BG and have tried stopping in DidResign itself.
The GPU calls are made only if there is a new video capture frame from the device sensor, which I presume will be suspended by iOS when it enters background. So the below stack trace could only be firing when the app is re-started or just before it officially suspended ???
Does anyone know of any Apple or other iOS/OpenGL alloc/release protocol one needs to follow when app enters bg and reactivated? More importantly, is there a clean way to clear/release all the OpenGL/GPUImage framebuffers/textures/context, etc and reinitialize everything?
Part of the stack trace is as below where it crashes with 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
Not sure if I had the same problem but I did get a EXC_BAD_ACCESS error when application was put in background.
I was able to solve it by pausing (and resuming) the video preview when app enters background.
Bind the application to notify you of background/foreground activity after 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];
}
And add these after stopping the camera with GPUImageVideoCamera stopCameraCapture and in your dealloc method:
- (void)removeObservers {
[[NSNotificationCenter defaultCenter]removeObserver:self
name:UIApplicationDidEnterBackgroundNotification
object:nil];
[[NSNotificationCenter defaultCenter]removeObserver:self
name:UIApplicationDidBecomeActiveNotification
object:nil];
}
And use these callbacks for the state changes (I'm unsure if there is any namespace collision with these method names, although I haven't had any):
- (void)applicationDidBecomeActive:(NSNotification *)notification {
[self.videoCamera resumeCameraCapture];
}
- (void)applicationDidEnterBackground:(NSNotification *)notification {
// TODO: Stop recording if recording in progress
[self.videoCamera pauseCameraCapture];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With