public void GetPointMapping(ref LEAP_POINT_MAPPING pm) { UInt64 size = 0; IntPtr buffer = IntPtr.Zero; while (true) { eLeapRS result = LeapC.GetPointMapping(_leapConnection, buffer, ref size); if (result == eLeapRS.eLeapRS_InsufficientBuffer) { if (buffer != IntPtr.Zero) { Marshal.FreeHGlobal(buffer); } buffer = Marshal.AllocHGlobal((Int32)size); continue; } reportAbnormalResults("LeapC get point mapping call was ", result); if (result != eLeapRS.eLeapRS_Success) { pm.nPoints = 0; pm.points = null; pm.ids = null; return; } break; } LEAP_POINT_MAPPING_INTERNAL pmi; StructMarshal <LEAP_POINT_MAPPING_INTERNAL> .PtrToStruct(buffer, out pmi); Int32 nPoints = (Int32)pmi.nPoints; pm.frame_id = pmi.frame_id; pm.timestamp = pmi.timestamp; pm.nPoints = pmi.nPoints; pm.points = new LEAP_VECTOR[nPoints]; pm.ids = new UInt32[nPoints]; float[] points = new float[3 * nPoints]; Int32[] ids = new Int32[nPoints]; Marshal.Copy(pmi.points, points, 0, 3 * nPoints); Marshal.Copy(pmi.ids, ids, 0, nPoints); int j = 0; for (int i = 0; i < nPoints; i++) { pm.points[i].x = points[j++]; pm.points[i].y = points[j++]; pm.points[i].z = points[j++]; pm.ids[i] = unchecked ((UInt32)ids[i]); } Marshal.FreeHGlobal(buffer); }