Search Unity

Concurrent NativeQueue crash

Discussion in 'Entity Component System' started by Geomatik, May 17, 2018.

  1. Geomatik

    Geomatik

    Joined:
    Jan 9, 2018
    Posts:
    2
    Hello, I started playing with ECS & Job system and I'm facing an unity crash.

    I have a simple Job that hash positions in an hash map and stores keys into a concurrent NativeQueue.

    It works as expected with a NativeList cast to a NativeArray thanks to ToDeferredJobArray(), but when I tried with a NativeQueue each attempts crash.

    Here's the job.

    Code (CSharp):
    1.  
    2. [ComputeJobOptimization]
    3. struct HashPositions : IJobParallelFor
    4. {
    5.     [ReadOnly] public ComponentDataArray<PositionByte> positions;
    6.     [ReadOnly] public ComponentDataArray<Status> status;
    7.  
    8.     [WriteOnly] public NativeHashMap<ulong, PositionByte>.Concurrent hashMap;
    9.     [WriteOnly] public NativeQueue<ulong>.Concurrent keys;
    10.  
    11.      public void Execute(int index)
    12.       {
    13.           if (!status[index].IsVisible() || !status[index].IsAlive())
    14.               return;
    15.  
    16.           var hash = HashUtility.Hash(positions[index].GetFlattenIndex());
    17.           hashMap.TryAdd(hash, positions[index]);
    18.           keys.Enqueue(hash);
    19.       }
    20. }
    And this is how I call my job on the main thread.

    Code (CSharp):
    1.  
    2. var positions = m_VolumeGroup.GetComponentDataArray<PositionByte>();
    3. var status = m_VolumeGroup.GetComponentDataArray<Status>();
    4. var hashMap = new NativeHashMap<ulong, PositionByte>(positions.Length, Allocator.TempJob);
    5. var keys = new NativeQueue<ulong>(Allocator.TempJob);
    6.              
    7.  var hashPositionsJob = new HashPositions()
    8.         {
    9.             positions = positions,
    10.             status = status,
    11.             hashMap = hashMap,
    12.             keys = keys
    13.         }.Schedule(positions.Length, 32, inputDeps);
    14.  
    Any idea of what I'm doing wrong ?
     

    Attached Files:

    Last edited: May 18, 2018
  2. Geomatik

    Geomatik

    Joined:
    Jan 9, 2018
    Posts:
    2
    Ok, it seems that this is the [ComputeJobOptimization] attribute which crashes my editor.

    I removed it and everything works fine.
     
  3. deplinenoise

    deplinenoise

    Unity Technologies

    Joined:
    Dec 20, 2017
    Posts:
    33
    Thanks for the report, and sorry for the lack of response.

    We've reduced this testcase and we're tracking it internally.
     
    yc960 and avvie like this.