0

I've got an application with a primary UIViewController, and a secondary one that is meant to be presented modally after a button is tapped.

Both of the UIViewControllers have their own GPUImageStillCamera with a corresponding GPUImageView added as a subview. Everything works fine up to this point.

However, when I go to the modally presented UIViewController and close it, the camera on my primary controller stays frozen on the last frame I left it on before presenting the second controller.

What I call in the PrimaryViewController

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];

    [_stillCamera resumeCameraCapture];
}

-(void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];

    [_stillCamera pauseCameraCapture];
}

What I call in my SecondaryViewController

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];

    [_stillCamera resumeCameraCapture];
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];

    [_stillCamera stopCameraCapture];
}

I'm 100% sure that the methods fire (checked with breakpoints). Logically, the first camera should just resume preview, once its viewed again, but it doesn't - it freezes at the last frame (when the the pauseCameraCapture method is called. Is there some way to force it to refresh (beside recreating it again)? I've checked - it isn't deallocated either.

What am I missing?

Martin Herman
  • 888
  • 13
  • 34
  • Try changing the Primary VC to use the 'will' appear/disappear instead of 'did' appear/disappear. Not sure if it will help but worth a shot. – TigerCoding Sep 28 '14 at 22:04

1 Answers1

0

I ended up with creating a Singleton class which keeps a single instance of GPUImageStillCamera alive. It also keeps all the filters in it and handles pausing/resuming when the app changes state.

The Singleton is also capable of returning a GPUImageView instance to preview the camera and destroying it when you don't need it anymore.

It uses a dummy shader (included), because you wouldn't be able to capture without a filter in the current version of GPUImage

See MHCameraManager here.

Martin Herman
  • 888
  • 13
  • 34