New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] AR Foundation TryAcquireLatestCPUImage broken (IOS 16.2) #1057
Comments
Add logic and get "TryAcquireLatestCpuImage" every X second (0.5f or 1) in place of every frame that will resolve your problem... |
Hi @Unity3D-Hardik, what do you mean with "login" exactly? |
The code you have provided will always cause the camera to freeze. Failing to dispose the The solution here should be to check the result of For more information see our Camera Image docs: https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@4.2/manual/cpu-camera-image.html. (I've linked the 4.2 version here because we are currently in the process of releasing 5.0.4, and the new release has changed the structure of the Camera docs which will cause URL's to break) |
Sorry, that was a typo. In place of every frame try to get TryAcquireLatestCpuImage on every 0.5f or 1 second.. If you want i can share logic. |
Hi @andyb-unity thanks for reaching out, Seems that I indeed forgot to dispose the image and this was the cause for the preview locking up. I did however still have problems I couldn't figure out causing it to freeze even when dispose was called. I was able to fix this by creating a seperate class that just fires an event whenever an image is available: using UnityEngine;
using UnityEngine.XR.ARFoundation;
using UnityEngine.XR.ARSubsystems;
public class XRCpuImageFetcher : 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)){
ImageAvailable?.Invoke(image);
image.Dispose();
}
}
public delegate void ImageAvailableDelegate(XRCpuImage image);
public event ImageAvailableDelegate ImageAvailable;
} Seems that it's really finicky. @Unity3D-Hardik Seems that if you've had the same problem, you might want to try this. |
Hii, I'm encountering a similar issue with TryAcquireLatestCpuImage, but before trying to figure out what causes my errors, I want to investigate if I'm trying the right method. I want to capture the camera feed, without GUI and instantiated augmented 3D objects. There's not much I can find about this method, do you guys know if this is a proper solution for my case? Does TryAcquireLatestCpuImage even return a clean camera feed? I know this question was closed, but maybe someone can answer me anyways :) |
Thanks for letting us know. As I previously mentioned, we have made a significant update to the Camera docs for the 5.0.4 patch. One of the changes is that all the sample code is now compiled as part of our package tests, so this error has been fixed and future similar errors on this page are highly unlikely. |
Alright, thanks for the help @andyb-unity ! |
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:
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
The text was updated successfully, but these errors were encountered: