Main camera not updating the buffer when comes from background to foreground

Hi, My camera access method is like this

    func processCameraUpdates() async {
        print("Process camera called")
        let formats = CameraVideoFormat.supportedVideoFormats(for: .main, cameraPositions:[.left])
        
        guard let cameraFrameUpdates =
            cameraFrameProvider.cameraFrameUpdates(for: formats[0]) else {
            return
        }
        
        for await cameraFrame in cameraFrameUpdates {
            guard let mainCameraSample = cameraFrame.sample(for: .left) else {
                continue
            }
            pixelBuffer = mainCameraSample.pixelBuffer
            print("Pixel buffer updated)")
           
           
        }
    }

In my ImmersiveSpace I am calling that method in this way

task {
            // Main camera access
            await placeManager.processCameraUpdates()
        }

This works fine as long as app is in active / opened / foreground. Once I close the app and re-open, I cannot capture any image. What am I missing here? Do I need to do something when scene become active?

Answered by Vision Pro Engineer in 802101022

Hi @rands

I suspect the provider is no longer running. Confirm this by checking its state cameraFrameProvider.state == .running. If that's the cause, create a new ARKitSession and invoke run passing the provider.

Accepted Answer

Hi @rands

I suspect the provider is no longer running. Confirm this by checking its state cameraFrameProvider.state == .running. If that's the cause, create a new ARKitSession and invoke run passing the provider.

@Vision Pro Engineer

Thanks for the response. When I check the status, it shows as paused. In my RealityView make part, I have already called the `ARKitSession


Task {
        await placeManager.runArkitSession()
     }

and then after the attachment block, I am calling my camera method.


 .task {
            // Main camera access
        await placeManager.processCameraUpdates()
      }

When I print a statement, processCameraUpdates() seems fire before the runArkitSession(). But this is not a problem when app opens fresh. Even after app become foreground, still my anchors are updating and I can see attachments, and scene renders correctly. Why only camera has the issue? If I call arkitsession.run again will it be a problem?

Main camera not updating the buffer when comes from background to foreground
 
 
Q