promet / PRAugmentedReality

iOS Augmented Reality Framework
http://praugmentedreality.com/
MIT License
606 stars 162 forks source link

Displaying UIImagePickerController sourceTypeCamera after starting PRARManager causes camera visual to freeze #49

Open MattMur opened 9 years ago

MattMur commented 9 years ago

Here is the flow that is causing this freezing behavior:

  1. ViewController is loaded
  2. In viewDidLoad method AR data points are initialized and handed to PRARManager to start AR (this works fine)
  3. At any moment user can take picture of their surrounding with UIImagePickerController sourceTypeCamera.
  4. User clicks button to display camera control.
  5. User finishes taking picture OR cancels
  6. At this point, AR Camera feed is frozen. AR Data points are still rendered correctly in place, but the camera feed is stuck and won't refresh.

I've tried stoping PRARManager before displaying camera, and then starting after camera is finished, but no luck. Something about loading UIImagePickerController breaks PRARManager's camera feed.

I'll report if I find any fixes

MattMur commented 9 years ago

Found a couple of things, foremost being the pod spec is not pulling the latest code changes!

Was able to fix the issue by pulling latest code changes, and then initializing new PRARManager after coming back from UIImagePickerController. I also made sure to clear out the old camera layers from the view:

- (void)prarDidSetupAR:(UIView *)arView withCameraLayer:(AVCaptureVideoPreviewLayer*)cameraLayer
      andRadarView:(UIView*)radar {
    // Clear old
    [[self.ARView viewWithTag:AR_VIEW_TAG] removeFromSuperview];
    [self.ARView.layer setSublayers:@[]];

    // Set new
    [self.ARView.layer addSublayer:cameraLayer];
    [self.ARView addSubview:arView];
    [self.ARView addSubview:radar];
}