在didUpdateFrame方法中保存ARSCNView快照会导致相机冻结

时间:2017-07-24 13:59:16

标签: ios objective-c github arkit

我在会话期间在ARKit中创建视频。当我按下录制按钮时,相机会冻结。我在didUpdateFrame委托中编写了导致问题的代码。在那里我保存了一个数组中的scene.snapshot。此外,当我从这些图像创建视频时,应用程序在调试器中崩溃并显示以下消息: 来自调试器的消息:由于内存问题而终止

    -(void)session:(ARSession *)session didUpdateFrame:(ARFrame *)frame
    {
     if (_recordButton.state  == UIControlStateSelected)
     {
      currentState = Recording;
     [self saveImage];
    }
    else if (previousState == Recording)
    {
    NSLog(@"Stop recording");
    currentState = NotRecording;
    recordTime = NULL;
    self.nextButton.enabled=YES;
   }
//update recording state per frame update
previousState = currentState;

}

    -(void)saveImage 
    {
      UIImage *image = self.sceneView.snapshot;
      [self.bufferArray addObject:image];
      image = nil;
   }

1 个答案:

答案 0 :(得分:2)

不要使用ARSCNView.snapshot来实现ARSessionDelegate.didUpdateFrame。我有同样的问题,解决方案是不实现ARSessionDelegate.didUpdateFrame。我已经将CADisplayLink与ARSCNView.snapshot一起使用,效果很好。 我也尝试使用ARFrame.capturedImage,但它根本不包含AR对象。 ARSCNView.snapshot包含它们。

相关问题