New buildin Tango api crashes in 2017.2.0b4

trying to get camera image but it crashes, im doing it right?

void Start()
    {
        Debug.Log ("Start");
        TangoDevice.Connect(new TangoConfig() { enableColorCamera = true, enableDepth = true, enableMotionTracking = true });
        line = Instantiate(m_lineRenderer);

        var br = new ARBackgroundRenderer ();
        br.camera = GameObject.Find("CameraImage").GetComponent<Camera>();
        mat.mainTexture = new Texture2D(0, 0, TextureFormat.RGBA32, false);
        br.backgroundMaterial = mat;
        br.backgroundRendererChanged += BrOnBackgroundRendererChanged;
        br.mode = ARRenderMode.MaterialAsBackground;
        TangoDevice.backgroundRenderer = br;
    }

    private void BrOnBackgroundRendererChanged()
    {
        Debug.Log("BrOnBackgroundRendererChanged");
    }

error
AndroidPlayer(ADB@127.0.0.1:34999) Could not get a pose for the latest image buffer at time 161744.275238. Error code 0-2
UnityEngine.XR.Tango.TangoDevice:TryGetLatestPointCloudInternal(Object, UInt32&, Double&)
UnityEngine.XR.Tango.TangoDevice:TryGetLatestPointCloud(PointCloudData&) (at /Users/builduser/buildslave/unity/build/artifacts/generated/common/modules/AR/TangoBindings.gen.cs:184)
NewBehaviourScript:Update() (at D:\Users\Igor\Documents\New Unity Project 17\Assets\NewBehaviourScript.cs:54)

[./Runtime/AR/Tango/TangoDevice.cpp line 206]
(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/modules/AR/TangoBindings.gen.cs Line: 184)

Hi friuns,
Unfortunately, this is a known issue in Google Tango SDK. Google recommends using Unity 5.6 until they come up with a better solution.

1 Like

Correction, this actually appears to be a separate issue.

Hi @friuns -

Thanks for reporting the crash! Your usage of the ARBackground renderer is not quite correct. You will need to create a Resources directory in Assets and create a material there that has its shader set to AR/TangoARRender. No need to attach a texture to this material as the background texture is created in an optimized way by Unity. Here is an example MonoBehavior you can use for the renderer setup:

public class ARRenderSetup : MonoBehaviour {

private UnityEngine.XR.ARBackgroundRenderer backgroundRenderer = new UnityEngine.XR.ARBackgroundRenderer();
private Material mat;

void Awake()
{
// First parameter is the name of your material in the Resources folder
mat = Resources.Load(ā€œTangoARBackgroundā€, typeof(Material)) as Material;
}

// Use this for initialization
void Start ()
{
// Associate this background renderer object with Tango
UnityEngine.XR.Tango.TangoDevice.backgroundRenderer = backgroundRenderer;

// Associate the rendererā€™s background material with the material in your Resources folder
backgroundRenderer.backgroundMaterial = mat;
backgroundRenderer.mode = UnityEngine.XR.ARRenderMode.MaterialAsBackground;
}
}

This MonoBehavior moves the Unity camera in sync with the position of the Tango camera:

public class CameraMovement : MonoBehaviour {
void Update () {
UnityEngine.XR.Tango.PoseData pose;

if (UnityEngine.XR.Tango.TangoInputTracking.TryGetPoseAtTime(out pose, UnityEngine.XR.Tango.CoordinateFrame.StartOfService, UnityEngine.XR.Tango.CoordinateFrame.CameraColor)) {
Camera.main.transform.position = pose.position;
Camera.main.transform.rotation = pose.rotation;
}
}
}

This MonoBehavior properly initializes Tango for a simple AR scene (no depth camera).

public class TangoConnection : MonoBehaviour
{
private TangoConfig tangoAPIConfig = new TangoConfig();

#if UNITY_EDITOR
// A camera field already exists in MonoBehavior for Editor-only,
// so use the new keyword there to silence a warning about it.
public new Camera camera;
#else
// The runtime doesnā€™t have this problem, so donā€™t use the
// new keyword here.
public Camera camera;
#endif

private Nullable m_VerticalFov = null;
private Nullable m_HorizontalFov = null;

void Awake()
{
tangoAPIConfig.enableMotionTracking = true;
tangoAPIConfig.enableColorCamera = true;
tangoAPIConfig.enableDepth = false;

if (TangoDevice.Connect(tangoAPIConfig))
TangoDevice.synchronizeFramerateWithColorCamera = false;
else
Debug.LogWarning(ā€œTango failed to connect!ā€);
}

protected Nullable GetCameraFov(ScreenOrientation screenOrientation)
{
if ((screenOrientation == ScreenOrientation.Portrait) ||
(screenOrientation == ScreenOrientation.PortraitUpsideDown))
{
if (m_HorizontalFov == null)
{
float fov;
if (TangoDevice.TryGetHorizontalFov(out fov))
m_HorizontalFov = fov;
}

return m_HorizontalFov;
}
else
{
if (m_VerticalFov == null)
{
float fov;
if (TangoDevice.TryGetVerticalFov(out fov))
m_VerticalFov = fov;
}

return m_VerticalFov;
}
}

protected virtual void SetCameraFov()
{
if (camera != null)
{
Nullable cameraFov = GetCameraFov(Screen.orientation);

if (cameraFov != null)
camera.fieldOfView = cameraFov.Value;
}
}

void OnDestroy()
{
TangoDevice.Disconnect();
}

void Update()
{
SetCameraFov();
}
}

Please reply to the thread if you have further questions.

-Best,
Mike Durand

Hi. Is there any example project for the new built-in Tango API?

1 Like

Hi @mdurand

still getting crash

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.XR;
using UnityEngine.XR.Tango;

public class NewBehaviourScript : MonoBehaviour
{
    public Camera tmpCam;
    // Use this for initialization
    private UnityEngine.XR.ARBackgroundRenderer br = new UnityEngine.XR.ARBackgroundRenderer();
    void Start()
    {
        Debug.Log ("Start");
        if(TangoDevice.Connect(new TangoConfig() { enableColorCamera = true, enableDepth = true, enableMotionTracking = true }))
            TangoDevice.synchronizeFramerateWithColorCamera = false;
        line = Instantiate(m_lineRenderer);

      
        TangoDevice.backgroundRenderer = br;
        br.camera = GameObject.Find("CameraImage").GetComponent<Camera>();
        //mat.mainTexture = new Texture2D(0, 0, TextureFormat.RGBA32, false);
        mat = Resources.Load("TangoARBackground", typeof(Material)) as Material;
        br.backgroundMaterial = mat;
        br.backgroundRendererChanged += BrOnBackgroundRendererChanged;
        br.mode = ARRenderMode.MaterialAsBackground;
    }

    private void BrOnBackgroundRendererChanged()
    {
        Debug.Log("BrOnBackgroundRendererChanged");
    }
    public Material mat;
    //ARBackgroundRenderer br;
    LineRenderer line;
    //private Texture2D tx;
    // Update is called once per frame
    void Update()
    {
        //var g = TangoDevice.backgroundRenderer;
        PoseData data;
        float fov;
        if (TangoDevice.TryGetVerticalFov(out fov))
            tmpCam.fieldOfView = Camera.main.fieldOfView = fov;
        if (TangoInputTracking.TryGetPoseAtTime(CoordinateFrame.StartOfService, CoordinateFrame.Device, out data))
        {
            Camera.main.transform.position = data.position;
            Camera.main.transform.rotation = data.rotation;
        }
        TangoDevice.TryGetLatestPointCloud(ref pointCloudData);
        //if (TangoDevice.TryGetLatestImageData(ref img))
        //{
        //    if (tx != null)
        //        DestroyImmediate(tx);

        //    tx = new Texture2D((int)img.width, (int)img.height);
        //    var extractArrayFromList = (byte[])Marshal.ExtractArrayFromList(img.data);
        //    Debug.Log(extractArrayFromList.Length);
        //    Debug.Log(tx.LoadImage(extractArrayFromList));
        //    tx.Apply(false);
        //}


        if (Input.GetMouseButton(0))
            Bum(Input.mousePosition);

        if (Input.GetMouseButtonUp(0))
        {
            ls.Add(line);
            line = Instantiate(m_lineRenderer);
            points = new List<Vector3>();
        }
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            foreach (var a in ls)
                Destroy(a.gameObject);
            ls.Clear();
        }

    }
    ImageData img;

    public RawImage m;
    private void Bum(Vector2 touchPosition)
    {
        int pointIndex = FindClosestPoint(touchPosition, 10);
        if (pointIndex > -1)
        {
            var mPoint = pointCloudData.points[pointIndex];
            mPoint = Camera.main.transform.TransformPoint(mPoint);
            points.Add(mPoint);
            line.positionCount = points.Count;
            line.SetPositions(points.ToArray());
        }
    }

    public List<Vector3> points = new List<Vector3>();
    List<LineRenderer> ls = new List<LineRenderer>();
    public LineRenderer m_lineRenderer;
    void OnGUI()
    {
        GUILayout.Label("p:" + pointCloudData.points.Count);

    }
    public int FindClosestPoint(Vector2 pos, int maxDist = 10)
    {
        int bestIndex = -1;
        float bestDistSqr = 0;

        var ray = tmpCam.ScreenPointToRay(pos);
        for (int it = 0; it < pointCloudData.points.Count; ++it)
        {
            float distSqr = Vector3.Cross(ray.direction, (Vector3)pointCloudData.points[it] - ray.origin).sqrMagnitude;
            if (distSqr > maxDist * maxDist)
                continue;

            if (bestIndex == -1 || distSqr < bestDistSqr)
            {
                bestIndex = it;
                bestDistSqr = distSqr;
            }
        }

        return bestIndex;
    }


    private PointCloudData pointCloudData;
}

unity 2017.2.0b5

and unity 2017.2.0b7 crash, with using scripts you provided

I think an example project on GitHub, BitBucket or in other way would be better for us.

08-19 15:18:54.132 8813-8825/? W/Unity: Tango failed to connect!

(Filename: ./artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)

It doesnā€™t crash in my case. But it canā€™t connect to the Tango.

I updated the core to m21. But it still canā€™t connect to the Tango Core.

The title seems to say that Tango is built-in to Unity. Is this the case?

1 Like

Itā€™s native integration in 2017.2 instead of the TangoSDK.

1 Like

@mdurand Could you please help?

@mdurand Itā€™s able to connect Tango now after I check the XR settings.
But it crashes if I use the ARRenderSetup.
And hereā€™s crash log.

08-26 16:54:17.659 13562-13603/empty.empty.empty I/tango_client_api: TangoErrorType TangoService_getCameraIntrinsics(TangoCameraId, TangoCameraIntrinsics*): Getting camera intrinsicsā€¦
08-26 16:54:17.659 10080-10105/? I/TangoServer.cc: Tango Service: getCameraIntrinsics, internal status 0
08-26 16:54:17.661 13562-13603/empty.empty.empty I/tango_client_api: TangoErrorType TangoService_getCameraIntrinsics(TangoCameraId, TangoCameraIntrinsics*): Done getting camera intrinsics.

--------- beginning of crash

08-26 16:54:17.661 13562-13603/empty.empty.empty A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 13603 (UnityGfxDeviceW)
08-26 16:54:17.680 447-9679/? W/qdmemalloc: Gralloc using 4K chunk.
08-26 16:54:17.711 447-6208/? W/qdmemalloc: Gralloc using 4K chunk.
08-26 16:54:17.714 1393-5773/? D/PowerManagerService: updateWakeLockWorkSourceInternal: lock=22485117 [AudioMix], ws=null
08-26 16:54:17.745 447-484/? W/qdmemalloc: Gralloc using 4K chunk.
08-26 16:54:17.754 546-3718/? D/APM::AudioPolicyManager: stopOutput() output 6, stream 3, session 51
08-26 16:54:17.763 541-541/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
08-26 16:54:17.763 541-541/? A/DEBUG: Build fingerprint: ā€˜Lenovo/phinny_prc/PB2PRO:6.0.1/MMB29M/PB2-690N_S200027_161214:user/release-keysā€™
08-26 16:54:17.763 541-541/? A/DEBUG: Revision: ā€˜0ā€™
08-26 16:54:17.763 541-541/? A/DEBUG: ABI: ā€˜armā€™
08-26 16:54:17.764 541-541/? A/DEBUG: pid: 13562, tid: 13603, name: UnityGfxDeviceW >>> empty.empty.empty <<<
08-26 16:54:17.764 541-541/? A/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0
08-26 16:54:17.778 447-482/? W/qdmemalloc: Gralloc using 4K chunk.
08-26 16:54:17.776 541-541/? W/debuggerd: type=1400 audit(0.0:1185): avc: denied { search } for name=ā€œcom.google.tangoā€ dev=ā€œdm-0ā€ ino=508055 scontext=u:r:debuggerd:s0 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0
08-26 16:54:17.789 541-541/? A/DEBUG: r0 00000000 r1 00000001 r2 de449a18 r3 de449930
08-26 16:54:17.789 541-541/? A/DEBUG: r4 00000008 r5 ac4b76e0 r6 00000004 r7 00000000
08-26 16:54:17.789 541-541/? A/DEBUG: r8 00000438 r9 007e9000 sl 00000001 fp 00000780
08-26 16:54:17.789 541-541/? A/DEBUG: ip de449a78 sp de449268 lr e1b4be58 pc e177b54c cpsr 400f0010
08-26 16:54:17.810 541-541/? A/DEBUG: backtrace:
08-26 16:54:17.810 541-541/? A/DEBUG: #00 pc 0049b54c /data/app/empty.empty.empty-1/lib/arm/libunity.so (_ZN9Texture2D11InitTextureEii13TextureFormatNS_10EInitFlagsEiii+988)
08-26 16:54:17.810 541-541/? A/DEBUG: #1 pc 00d9bd34 /data/app/empty.empty.empty-1/lib/arm/libunity.so (_ZN5Tango11ARRendering29UpdateExternalTextureCallbackEi+368)
08-26 16:54:17.810 541-541/? A/DEBUG: #2 pc 00874ef4 /data/app/empty.empty.empty-1/lib/arm/libunity.so (_ZN9GfxDevice26InsertCustomMarkerCallbackEPFviEi+36)
08-26 16:54:17.810 541-541/? A/DEBUG: #3 pc 00960978 /data/app/empty.empty.empty-1/lib/arm/libunity.so (_ZN15GfxDeviceWorker10RunCommandER20ThreadedStreamBuffer+29328)
08-26 16:54:17.811 541-541/? A/DEBUG: #4 pc 00961e50 /data/app/empty.empty.empty-1/lib/arm/libunity.so (_ZN15GfxDeviceWorker6RunExtER20ThreadedStreamBuffer+32)
08-26 16:54:17.811 541-541/? A/DEBUG: #5 pc 009596c8 /data/app/empty.empty.empty-1/lib/arm/libunity.so (_ZN15GfxDeviceWorker18RunGfxDeviceWorkerEPv+108)
08-26 16:54:17.811 541-541/? A/DEBUG: #6 pc 00723c50 /data/app/empty.empty.empty-1/lib/arm/libunity.so (_ZN6Thread16RunThreadWrapperEPv+84)
08-26 16:54:17.811 541-541/? A/DEBUG: #7 pc 00041823 /system/lib/libc.so (_ZL15__pthread_startPv+30)
08-26 16:54:17.811 541-541/? A/DEBUG: #8 pc 00019285 /system/lib/libc.so (__start_thread+6)

Hi All-

Hopefully you have all seen the announcement on 8/29 about Unityā€™s support for Googleā€™s ARCore SDK which has superseded the Tango SDK that was available in earlier betas of 2017.2. As of 2017.2b9 the Tango APIs have been removed.

Please take a look at this forum post for instructions on how to use ARCore with your Pixel and S8 phones: Introducing ARCore: An Android AR SDK for Unity - Unity Engine - Unity Discussions

-Best,
Mike

1 Like

Can you advise what people still interested in developing for Tango do? I canā€™t get the Tango SDK examples to work on 2017.2b9 and I donā€™t own an ARCore-supported device to simply switch SDKā€™s.

Iā€™m sitting in the same boat. I found some intesting stuff in a thread on googles Github:
https://github.com/googlesamples/tango-examples-unity/issues/102

With these tricks I was able to prevent the app from crashing in Unity 2017.1 and 2017.2 beta but Iā€™m still not getting any camera data.

Iā€™m trying to go back to Unity 4.6.2 now to see if things work better.

The notice on Googleā€™s Tango developer site explains that it the legacy Tango SDK for Unity will only be the only path to support the ASUS and Lenovo Tango devices. ARCore does not support these devices.

-Best,
Mike

They arenā€™t supported YET.
It would be a very weird decision to not give the Zenfone ARcore support.
Considering the statement that by the end of the year 100 million phones are supposed to be ARcore compatible the list of devices will need to grow quite a bit.

Unity 4.6.2 works fine by the way, Iā€™m happily scripting away for Tango.