Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Bug Mesh collider with empty BVH locks main thread

Discussion in 'Physics for ECS' started by n3b, Oct 16, 2022.

  1. n3b

    n3b

    Joined:
    Nov 16, 2014
    Posts:
    56
    The BVH builder relies on aabbs length, while the empty array is the one with points.
    (sorry I don't have a proper project at hand to submit a bug)

    Physics_MeshCollider:
    Code (CSharp):
    1. var points = new NativeList<BoundingVolumeHierarchy.PointAndIndex>(primitives.Length, Allocator.Temp);
    2.                 var aabbs = new NativeArray<Aabb>(primitives.Length, Allocator.Temp);
    3.  
    4.                 for (int i = 0; i < primitives.Length; i++)
    5.                 {
    6.                     MeshConnectivityBuilder.Primitive p = primitives[i];
    7.  
    8.                     // Skip degenerate triangles
    9.                     if (MeshConnectivityBuilder.IsTriangleDegenerate(p.Vertices[0], p.Vertices[1], p.Vertices[2]))
    10.                     {
    11.                         continue;
    12.                     }
    13.  
    14.                     aabbs[i] = Aabb.CreateFromPoints(p.Vertices);
    15.                     points.Add(new BoundingVolumeHierarchy.PointAndIndex
    16.                     {
    17.                         Position = aabbs[i].Center,
    18.                         Index = i
    19.                     });
    20.                 }
    21.  
    22.                 var bvh = new BoundingVolumeHierarchy(nodes);
    23.  
    24.                 bvh.Build(points.AsArray(), aabbs, out numNodes, useSah: true);
    25.  

    BVHBuilder:
    Code (CSharp):
    1.  
    2. public unsafe void Build(NativeArray<PointAndIndex> points, NativeArray<Aabb> aabbs, out int nodeCount, bool useSah = false)
    3. {
    4.     m_Nodes[0] = Node.Empty;
    5.  
    6.     if (aabbs.Length > 0)
    7. ...
    8.  
     

    Attached Files: