Describe the bug
ARRaycastManager.RaycastFallback() produces wrong results if more than one m_Raycasters hit something (lines producing the bug). Please read the comments below:
int dstIndex = 0;
foreach (var hitArray in s_NativeRaycastHits)
{
NativeArray<XRRaycastHit>.Copy(hitArray, 0, allHits, dstIndex, hitArray.Length);
hitArray.Dispose(); // hitArray is disposed before accessing the hitArray.Length
dstIndex += hitArray.Length; // resulting in hitArray.Length being always zero. This ovewrites the hitArray if s_NativeRaycastHits > 1
}
To Reproduce
Let the ARRaycastManager.RaycastFallback() hit both ARPointCloud and ARPlane simultaneously.
Expected behavior
ARRaycastManager.RaycastFallback() returns an array containing all ARPointClouds and ARPlanes that were hit.
Actual behavior
Hits from the m_Raycasters[1] overwrite hits from the m_Raycasters[0].
Reproducible with
AR Foundation [3.0.1, 5.0.0-pre.8]
Describe the bug ARRaycastManager.RaycastFallback() produces wrong results if more than one m_Raycasters hit something (lines producing the bug). Please read the comments below:
To Reproduce Let the ARRaycastManager.RaycastFallback() hit both ARPointCloud and ARPlane simultaneously.
Expected behavior ARRaycastManager.RaycastFallback() returns an array containing all ARPointClouds and ARPlanes that were hit.
Actual behavior Hits from the m_Raycasters[1] overwrite hits from the m_Raycasters[0].
Reproducible with AR Foundation [3.0.1, 5.0.0-pre.8]
Proposed solution Rearrange the code as follows: