Search Unity

Bug AR Foundation TryAcquireLatestCPUImage broken

Discussion in 'iOS and tvOS' started by thomasvaniseghemSB, Feb 6, 2023.

  1. thomasvaniseghemSB

    thomasvaniseghemSB

    Joined:
    Sep 15, 2022
    Posts:
    13
    The following code results in the camera preview freezing on IOS. I've reliably narrowed it down to using the function TryAcquireLatestCpuImage(out XRCpuImage image). The cameraManager is present so this isn't the problem.
    Commenting TryAcquireLatestCpuImage results in the preview working again. Also tried turning of multithreaded rendering and putting it in the Update() function.
    Also can't see anything or any errors in the logs.

    Also the documentation at https://docs.unity3d.com/Packages/c...#accessing-the-device-camera-image-on-the-cpu contains an error. It should be "frameReceived" instead of "cameraFrameReceived".

    Platforms:
    Unity 2021.3.14f
    ARKit 5.0.3
    AR Foundation 5.0.3
    Xcode 14.1
    iPad Pro 3th gen IOS 16.2

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.XR.ARFoundation;
    3. using UnityEngine.XR.ARSubsystems;
    4.  
    5. public class TestXRCpuImage : MonoBehaviour
    6. {
    7.     public ARCameraManager cameraManager;
    8.  
    9.     void OnEnable()
    10.     {
    11.         cameraManager.frameReceived += FrameChanged;
    12.     }
    13.  
    14.     void OnDisable()
    15.     {
    16.         cameraManager.frameReceived -= FrameChanged;
    17.     }
    18.  
    19.     private void FrameChanged(ARCameraFrameEventArgs args){
    20.         if (!cameraManager.TryAcquireLatestCpuImage(out XRCpuImage image))
    21.             return;
    22.     }
    23.  
    24. }