Search Unity

ARPointCloud.GetPoints() throwing OutOfRange exceptions

Discussion in 'AR' started by vTimePawel, Jun 7, 2018.

  1. vTimePawel

    vTimePawel

    Joined:
    Aug 1, 2017
    Posts:
    32
    Hello,

    There seems to be a problem with the ARPointCloud's Points property.
    Running on a iOS 12 beta iPhone 8 with ARKit 2, the Vector3[] GetPoints() function always throws the mentioned exception when converting from float[] to vector3[].
    Logging lenghts of both arrays, I get values like:
    "GetPoints: pointCount 803
    GetPoints: verts 200"
    which clearly don't fit into each other nicely.
    Here's the original code with some logging inserted:
    Code (CSharp):
    1.  
    2. IntPtr pointsPtr = pointCloud_GetPointsPtr (m_Ptr);
    3. int pointCount = Count;
    4. Debug.Log("GetPoints: pointCount " + pointCount);
    5. if (pointCount <= 0 || pointsPtr == IntPtr.Zero)
    6. {
    7.     return null;
    8. }
    9. else
    10. {
    11.     // Load the results into a managed array.
    12.    float [] resultVertices = new float[pointCount];
    13.    Marshal.Copy(pointsPtr, resultVertices, 0, pointCount);
    14.  
    15.    Vector3[] verts = new Vector3[(pointCount / 4)];
    16.  
    17.    Debug.Log("GetPoints: verts " + verts.Length);
    18.  
    19.    for (int count = 0; count < pointCount; count++)
    20.    {
    21.       //convert to Unity coords system
    22.       verts[count / 4].x = resultVertices[count++];
    23.       verts[count / 4].y = resultVertices[count++];
    24.       verts[count / 4].z = -resultVertices[count++];
    25.    }
    26.  
    27.    return verts;
    28. }
    The code throws in the for loop, once (count / 4) reaches (verts.Length).
    I've re-built it to use verts.Length as counter instead and ignore the trailing couple of floats, but it looks like an error in the native code land somewhere:
    Code (CSharp):
    1.  
    2. int count = 0;
    3. for (int i = 0; i < verts.Length; i++)
    4. {
    5.     //convert to Unity coords system
    6.    verts[i].x = resultVertices[count++];
    7.    verts[i].y = resultVertices[count++];
    8.    verts[i].z = -resultVertices[count++];
    9.    count++;
    10. }