I am trying to synchronically grab the camera frame using the Camera API but the following fails and then never gets fired again, even though the AR features keep on working:
var cameraSubsystem = ARSubsystemManager.cameraSubsystem;
CameraImage image;
if (!cameraSubsystem.TryGetLatestImage(out image))
{
Debug.Log("Gets here once and then this event never gets fire again in the session");
return;
}
Am I missing something or might there be an issue? (I am running my apk on a Pixel 2 device, and building with Unity 2019.1.0f2).
Had that line of code been reached - then yes. But the event is only fired once, the “TryGetLatestImage” returns false and the event is not fired again even through I have not unregistered from it.
(I am returning from the method scope just like the example. I have just edited the original post to state that).
This is just a part of the whole code which was basically based on the sample code for this API so the dispose was not the problem.
I just had another line disabling the rest of the scope from running. Once removed:
it does work but there is one thing - it seems the first frame might be empty? Although the buffer length is a valid number and the code runs, once I encode the Texture2D - only the first actual image file is 0 bytes long (thus unreadable). The consecutive runs work as expected producing a valid buffer with actual image data.
if (!cameraSubsystem.TryGetLatestImage(out image))
return;
with
if (!cameraSubsystem.TryGetLatestImage(out image))
{
Debug.LogError(“getting latest image failed again”);
image.Dispose();
/// image is a struct, so it’s never null. Probably it only needs to be disposed if it has properly been used which would explain why they didn’t dispose it in the example code. Still, since it might be that trying-to-get-the-latest-image fails the first couple of times and would after that work, I’d still like to make sure it doesn’t fail because there are too many image instances Documentation says : The CameraImage is a struct which represents a native resource. When you are finished using it, you must call Dispose on it to release it back to the system. Although you may hold a CameraImage for multiple frames, most platforms have a limited number of them, so failure to Dispose them may prevent the system from providing new camera images. ///
return;
}
Debug.Log(“getting latest image succeeded for once”);
And I get spammed with the error log, and i never get past that.
This means the event gets called over and over, but the attempt to get the latest image just always fails.
Running it on iOS, so i think it has nothing to do with android. And the AR experience works other than that (tracked pose driver, ar camera background, ar plane manager, ar point cloud manager), it’s just getting the camera image to CPU that fails, returning false.
Any help or hints are much appreciated =)
edit: it actually works on android for me, but not on iOS