Search Unity

Burst compiler fails when I try to use an external dll

Discussion in 'Burst' started by Khorheal, Jul 31, 2021.

  1. Khorheal

    Khorheal

    Joined:
    Jan 2, 2018
    Posts:
    3
    In my project I'm using Jobs system for pathfinding. For the pathfinding I use an external dll for faster calculation. When I add [BurstCompile(CompileSynchronously = true)] to my job, the compiler gives an error saying;

    Burst error BC0101: Unexpected error while processing function `GridPathfinding.Execute(GridPathfinding* this)`: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.

    Did anyone else encountered this?
     
  2. tim_jones

    tim_jones

    Unity Technologies

    Joined:
    May 2, 2019
    Posts:
    287
    Hi @Khorheal - are you able to paste the code inside the `GridPathfinding.Execute` method here? That looks like a compiler bug, but we'd need to see the code to be able to investigate. Or if you'd prefer, you could submit a bug from the Editor, via Help > Report a Bug.
     
  3. Khorheal

    Khorheal

    Joined:
    Jan 2, 2018
    Posts:
    3
    Code (CSharp):
    1.     public void Execute()
    2.     {
    3.         SimplePriorityQueue<HexCoordinates> frontier = new SimplePriorityQueue<HexCoordinates>();
    4.         frontier.Enqueue(startingPoint, 0);
    5.         HexCoordinates[] cellRefs = new HexCoordinates[cells.Length];
    6.         cells.CopyTo(cellRefs);
    7.  
    8.         Dictionary<HexCoordinates, HexCoordinates> cameFrom = new Dictionary<HexCoordinates, HexCoordinates>();
    9.         Dictionary<HexCoordinates, double> costSoFar = new Dictionary<HexCoordinates, double>();
    10.  
    11.         cameFrom[startingPoint] = startingPoint;
    12.         costSoFar[startingPoint] = 0;
    13.  
    14.         while (frontier.Count > 0)
    15.         {
    16.             HexCoordinates current = frontier.Dequeue();
    17.  
    18.             if (current.Equals(destination))
    19.             {
    20.                 break;
    21.             }
    22.  
    23.             foreach (HexCoordinates next in current.GetNeighbours())
    24.             {
    25.                 HexCoordinates nextRef = System.Array.Find(cellRefs, cell => cell.Equals(next));
    26.                 double newCost = costSoFar[current]
    27.                     + (nextRef.isTraversable ? 5 : 1);
    28.                 if (!costSoFar.ContainsKey(nextRef)
    29.                     || newCost < costSoFar[nextRef])
    30.                 {
    31.                     costSoFar[nextRef] = newCost;
    32.                     double priority = newCost + GetCellDistance(nextRef, destination);
    33.                     frontier.Enqueue(nextRef, (float)priority);
    34.                     cameFrom[nextRef] = current;
    35.                 }
    36.             }
    37.         }
    38.  
    39.         HexCoordinates currentPath = destination;
    40.  
    41.         int i = 0;
    42.         while (!currentPath.Equals(startingPoint))
    43.         {
    44.             path[i] = currentPath;
    45.             currentPath = cameFrom[currentPath];
    46.             i++;
    47.         }
    48.  
    49.         path[i] = startingPoint;
    50.         pathLength[0] = i;
    51.     }
    As you can see it's a simple A* search. I'm using a commonly used Priority Queue from a dll. I watched using a debugger and It throw me an error when I instantiated SimplePriorityQueue.
     
  4. tim_jones

    tim_jones

    Unity Technologies

    Joined:
    May 2, 2019
    Posts:
    287
    My apologies, I missed your reply. Did you get any other details along with the original error?

    Usually there's more of a callstack to go along with an error message like that.
     
  5. Khorheal

    Khorheal

    Joined:
    Jan 2, 2018
    Posts:
    3
    It seems to have been fixed, strangely. I checked now and it seems to be working, I have updated my Unity a while ago so maybe it got patched. Still, thanks for the help!