Unity-Technologies / arfoundation-samples

Example content for Unity projects based on AR Foundation
Other
3.03k stars 1.13k forks source link

[Bug] TryAcquireLatestCpuImage doesn't work if ArFaceManager is enabled #599

Closed Liatian closed 3 years ago

Liatian commented 4 years ago

Describe the bug If ArFaceManager is enabled, the ARCameraManager TryAcquireLatestCpuImage(out XRCpuImage image) function stops returning true after 3 seconds of running.

To Reproduce Steps to reproduce the behavior:

  1. Go to 'Assets\Scenes\FaceTracking\FaceMesh
  2. Create a script with functions like this:
void OnEnable()
{
        if (this._arCameraManager != null)
        {
            this._arCameraManager.frameReceived += OnCameraFrameReceived;
        }
}

unsafe void OnCameraFrameReceived(ARCameraFrameEventArgs eventArgs)
{
        this._debugText.text = this._arCameraManager.TryAcquireLatestCpuImage(out XRCpuImage image).ToString();
        image.Dispose();
}
  1. Build and test on a tablet a FaceMesh scene with new features
  2. TryAcquireLatestCpuImage (out XRCpuImage image) returns true for the first 3 seconds and then always false

Expected behavior TryAcquireLatestCpuImage (out XRCpuImage image) returns true while the application is running

Actual behavior If ArFaceManager is enabled, TryAcquireLatestCpuImage (out XRCpuImage image) returns true only for the first 3 seconds, otherwise when ArFaceManager is disabled, the function always returns true

Tablet:

tdmowrer commented 4 years ago

I could not reproduce this on a Pixel 3 with the following:

using System;
using UnityEngine;
using UnityEngine.XR.ARFoundation;

[RequireComponent(typeof(ARCameraManager))]
public class GetCpuImage : MonoBehaviour
{
    ARCameraManager m_CameraManager;

    void Start()
    {
        m_CameraManager = GetComponent<ARCameraManager>();
        m_CameraManager.frameReceived += OnFrameReceived;
    }

    void OnFrameReceived(ARCameraFrameEventArgs eventArgs)
    {
        if (m_CameraManager.TryAcquireLatestCpuImage(out var image))
        {
            using (image)
            {
                Debug.Log($"{Time.realtimeSinceStartup}: Got image: {image}");
            }
        }
        else
        {
            Debug.Log($"{Time.realtimeSinceStartup} Could not acquire cpu image.");
        }
    }
}

It could be device specific. Have you reproduced this on any other Android devices?

tdmowrer commented 4 years ago

We were able to reproduce this on older versions of ARCore (Google Play Services for AR) but not the latest (1.19). What version do you currently have installed? If you go to the Play Store and update to the latest version, does that fix the problem for you?

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.