[Repost from IOS discussion, I think this is the right place.]
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/com.unity.xr.arfoundation@5.0/manual/features/camera.html#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
using UnityEngine;
using UnityEngine.XR.ARFoundation;
using UnityEngine.XR.ARSubsystems;
public class TestXRCpuImage : MonoBehaviour
{
public ARCameraManager cameraManager;
void OnEnable()
{
cameraManager.frameReceived += FrameChanged;
}
void OnDisable()
{
cameraManager.frameReceived -= FrameChanged;
}
private void FrameChanged(ARCameraFrameEventArgs args){
if (!cameraManager.TryAcquireLatestCpuImage(out XRCpuImage image))
return;
}
}
1 Like
Note: I think it might be related to the IOS 16 update. I had it working before I updated to IOS 16.
1 Like
ina
May 16, 2023, 10:55pm
4
Documentation needs to be updated
https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@5.1/manual/features/Camera/image-capture.html
opened 09:05AM - 07 Feb 23 UTC
closed 09:56AM - 08 Feb 23 UTC
bug
**Describe the bug**
The function `TryAcquireLatestCpuImage` causes the preview… to freeze on IOS.
**To Reproduce**
Steps to reproduce the behavior:
Put the following MonoBehaviour on a GameObject in the scene:
```csharp
using UnityEngine;
using UnityEngine.XR.ARFoundation;
using UnityEngine.XR.ARSubsystems;
public class TestXRCpuImage : MonoBehaviour
{
public ARCameraManager cameraManager;
void OnEnable()
{
cameraManager.frameReceived += FrameChanged;
}
void OnDisable()
{
cameraManager.frameReceived -= FrameChanged;
}
private void FrameChanged(ARCameraFrameEventArgs args){
if (!cameraManager.TryAcquireLatestCpuImage(out XRCpuImage image))
return;
}
}
```
Then build the app for IOS.
**Expected behavior**
The image is returned and nothing happens.
**Actual behavior**
The image is returned and the preview freezes, making the application unusable. No errors are logged to the console about this.
The application itself isn't locking up since all other functionallities still work like expected, it's just the camera preview.
It is important to note that this was working without problems before updating to IOS 16.2.
**Platform**
- Device: iPad Pro 3th gen
- OS: IOS 16.2
- Unity version: 2021.3.14f
- ARFoundation version: 5.0.2 & 5.0.3
- ARKit 5.0.2 & 5.0.3
- Xcode 14.1