public static bool PollDepth(IntPtr depthStreamHandle, bool isNearMode, ref short[] depthPlayerData) { IntPtr imageFramePtr = IntPtr.Zero; bool newDepth = false; if (isNearMode) { KinectWrapper.NuiImageStreamSetImageFrameFlags(depthStreamHandle, NuiImageStreamFlags.EnableNearMode); } else { KinectWrapper.NuiImageStreamSetImageFrameFlags(depthStreamHandle, NuiImageStreamFlags.None); } int hr = KinectWrapper.NuiImageStreamGetNextFrame(depthStreamHandle, 0, ref imageFramePtr); if (hr == 0) { newDepth = true; NuiImageFrame imageFrame = (NuiImageFrame)Marshal.PtrToStructure(imageFramePtr, typeof(NuiImageFrame)); INuiFrameTexture frameTexture = (INuiFrameTexture)Marshal.GetObjectForIUnknown(imageFrame.pFrameTexture); NuiLockedRect lockedRectPtr = new NuiLockedRect(); IntPtr r = IntPtr.Zero; frameTexture.LockRect(0, ref lockedRectPtr, r, 0); depthPlayerData = ExtractDepthImage(lockedRectPtr); frameTexture.UnlockRect(0); hr = KinectWrapper.NuiImageStreamReleaseFrame(depthStreamHandle, imageFramePtr); } return(newDepth); }