Search Unity

Burst + Collections 0.1 type error

Discussion in 'Burst' started by eizenhorn, Jul 31, 2019.

  1. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,684
    After upgrade to 0.1.0 packages,burst throw exception in first frame after loading scene where I build nodes graph and rebuild invalid nodes in locations with obstaces.
    In Bursted IJob on trying call Remove for NativeMultiHashMap:
    Code (CSharp):
    1.  
    2.                     bool initialNodeHasConnection =
    3.                         graph.TryGetFirstValue(node, out var connectedNode, out var connectedIt);
    4.                     while (initialNodeHasConnection)
    5.                     {
    6.                         if (connectedNode.Location != node.Location)
    7.                         {
    8.                             ...
    9.                         }
    10.                         else
    11.                         {
    12.                             graph.Remove(connectedNode, node); // <---- Here
    13.                         }
    14.  
    15.                         initialNodeHasConnection = graph.TryGetNextValue(out connectedNode, ref connectedIt);
    16.                     }
    Where graph is NativeMultiHashMap<PortalNode, PortalNode>.

    Error:
    Code (CSharp):
    1. E:\GAMEDEV\REPOSITORY\Elinor\Packages\com.unity.collections@0.1.0-preview\Unity.Collections\NativeHashMap.cs(1013,13): error: Accessing the type `MM.CrowdPathFinding.PortalNode` is not supported by burst
    2. at Unity.Collections.NativeMultiHashMap`2<MM.CrowdPathFinding.PortalNode,MM.CrowdPathFinding.PortalNode>.Remove(Unity.Collections.NativeMultiHashMap`2<MM.CrowdPathFinding.PortalNode,MM.CrowdPathFinding.PortalNode>* this, MM.CrowdPathFinding.PortalNode* key, MM.CrowdPathFinding.PortalNode* value) (at E:\GAMEDEV\REPOSITORY\Elinor\Packages\com.unity.collections@0.1.0-preview\Unity.Collections\NativeHashMap.cs:1013)
    3. at MM.CrowdPathFinding.RemoveNodesForInvalidLocations.Execute(MM.CrowdPathFinding.RemoveNodesForInvalidLocations* this) (at E:\GAMEDEV\REPOSITORY\Elinor\Assets\Scripts\Managers\Pathfinding\CrowdPathFindingJobs.cs:81)
    4. at Unity.Jobs.IJobExtensions.JobStruct`1<MM.CrowdPathFinding.RemoveNodesForInvalidLocations>.Execute(ref MM.CrowdPathFinding.RemoveNodesForInvalidLocations data, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, ref Unity.Jobs.LowLevel.Unsafe.JobRanges ranges, int jobIndex) (at C:\buildslave\unity\build\Runtime\Jobs\Managed\IJob.cs:30)
    5.  
    6.  
    7. While compiling job: System.Void Unity.Jobs.IJobExtensions/JobStruct`1<MM.CrowdPathFinding.RemoveNodesForInvalidLocations>::Execute(T&,System.IntPtr,System.IntPtr,Unity.Jobs.LowLevel.Unsafe.JobRanges&,System.Int32)
    It happens only once. Before 0.1.0 all works without any problems.

    In Burst Inspector it happens too:
    upload_2019-7-31_14-0-13.png

    It drops on
    if (typeof(TValueEQ) != typeof(TValue))
    on 1013 row of NativeMultiHashMap in NativeHashMap.cs in Collections package, previously I used TryRemove here but after upgrate it's not exists (cause WorldDiff removed).
    Type:
    Code (CSharp):
    1. public struct PortalNode : IEquatable<PortalNode>, IEquatable<int2>
    2.     {
    3.         public int2         Coords;
    4.         public int          Cost;
    5.         public int          Location;
    6.         public int          Width;
    7.         public LocationSide Side;
    8.  
    9.         public static bool operator ==(PortalNode n1, PortalNode n2)
    10.         {
    11.             return math.all(n1.Coords == n2.Coords);
    12.         }
    13.  
    14.         public static bool operator !=(PortalNode n1, PortalNode n2)
    15.         {
    16.             return !math.all(n1.Coords == n2.Coords);
    17.         }
    18.  
    19.         public bool Equals(PortalNode other)
    20.         {
    21.             return Coords.Equals(other.Coords);
    22.         }
    23.  
    24.         public bool Equals(int2 other)
    25.         {
    26.             return Coords.Equals(other);
    27.         }
    28.  
    29.         public override int GetHashCode()
    30.         {
    31.             return Coords.GetHashCode();
    32.         }
    33.     }
     
    Last edited: Jul 31, 2019
  2. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,684
    Meh my bad, cause previously I used TryRemove from WorldDiff HashMapUtility and it's used iterator for removing without type comparsion (which of course not work in Burst) and it works in burst.
     
  3. Deleted User

    Deleted User

    Guest

    Wait, do you mean ECB works in Burst now?
     
  4. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    Yes, @Joachim_Ante mentioned that in one of the threads.

    Its supported only on 2019.3 I think.
     
  5. davidv_unity

    davidv_unity

    Unity Technologies

    Joined:
    Nov 14, 2018
    Posts:
    15
    Hi eizenhorn, just confirming you are correct, the overload you initially used is not burstable as the actual Types are compared in the collection check (the implementation you posted where the instances are compared is fine). We'll fix that. The other overloads are burstable (a workaround would be to get the iterator to that element and call Remove on that, e.g. through TryGetFirstValue). Sorry for the inconvenience!
     
    eizenhorn likes this.
  6. xoofx

    xoofx

    Unity Technologies

    Joined:
    Nov 5, 2016
    Posts:
    417
    The message is not clear enough, it should be instead "Accessing `typeof(MM.CrowdPathFinding.PortalNode)` is not supported by burst"
    But actually, we need to support this scenario (comparing typeof for example with generics) so we will try to bring this in a near future release
     
    eizenhorn likes this.
  7. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,684
    It’s not about ECB it’s about NMHM.

    Yep like I did before, I used extension from WorldDiff and just forgot that, and after update to 0.1 WorldDiff removed, thus TryRemove removed :) Anyway it’s easy to implement :)
    Agree my first thought was “Hey my type now not burstable!” Only after source looking I found real reason.
     
  8. Deleted User

    Deleted User

    Guest

    Alexandre, I am sorry for the off topic, but would not you mind to answer this quick question?
    https://forum.unity.com/threads/burst-1-1-1-new-release.709280/#post-4794989