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. Dismiss Notice

Bug Native stream Bug in IJobChunk with entities 0.16.0-preview.21 and 0.17.0-preview.41

Discussion in 'Entity Component System' started by WAYNGames, Jan 10, 2021.

  1. WAYNGames

    WAYNGames

    Joined:
    Mar 16, 2019
    Posts:
    938
    Hello,

    I suspecting a bug with the native stream.
    I have an IJobChunk using a NativeStream.Writer.

    That wirter is created with a foreach count equal to the number of chunk the job runs on.
    Code (CSharp):
    1. new NativeStream(_query.CalculateChunkCount(), Allocator.TempJob);
    The in the job I write to the stream begining with :
    Code (CSharp):
    1. Writer.BeginForEachIndex(chunkIndex);
    That works if I have only one chunk.
    My chunk cna contain 55 entities. As soon as I add a 56th entity, the job throw that error :
    Code (CSharp):
    1. ArgumentException: Index 1 is out of restricted IJobParallelFor range [55...55] in NativeStream.
    From that message I assume I was using hte wrong index in hte jobchunk so I switched to :
    Code (CSharp):
    1. Writer.BeginForEachIndex(firstEntityIndex);
    Now firstEntityIndex is 0 for the first chunk and 55 for the second so teh first chunk works fine and the second is in the requested range [55...55]. But now I get these errors :
    Code (CSharp):
    1. AssertionException: Assertion failure. Value was False
    2. Expected: True
    3. UnityEngine.Assertions.Assert.Fail (System.String message, System.String userMessage) (at <bad59441812943c7b8d5a5ba85795810>:0)
    4. UnityEngine.Assertions.Assert.IsTrue (System.Boolean condition, System.String message) (at <bad59441812943c7b8d5a5ba85795810>:0)
    5. UnityEngine.Assertions.Assert.IsTrue (System.Boolean condition) (at <bad59441812943c7b8d5a5ba85795810>:0)
    6. Unity.Collections.NativeStream+Writer.CheckBeginForEachIndex (System.Int32 foreachIndex) (at Library/PackageCache/com.unity.collections@0.14.0-preview.16/Unity.Collections/NativeStream.cs:392)
    7. Unity.Collections.NativeStream+Writer.BeginForEachIndex (System.Int32 foreachIndex) (at Library/PackageCache/com.unity.collections@0.14.0-preview.16/Unity.Collections/NativeStream.cs:302)
    Code (CSharp):
    1. ArgumentException: BeginForEachIndex can only be called once for the same index (55).
    So now I'm a bit lost...
     
  2. WAYNGames

    WAYNGames

    Joined:
    Mar 16, 2019
    Posts:
    938
    I copied the package in local to add some logs and the only thing that make sense is that the PatchMinMaxRange is not called when the jobchunk is executed.

    This may be due to my update to entity 0.16.0-preview.21 with unity 2020.1.17f1.

    For now I worked around it by calling
    Code (CSharp):
    1. Writer.PatchMinMaxRange(chunkIndex);
    ConsumerWriter.PatchMinMaxRange(chunkIndex); before
    Code (CSharp):
    1. Writer.BeginForEachIndex(chunkIndex);
    . This does not throw any errors, and the entities updated using the stream data are properly updated so it will do for now I guess.
     
    Last edited: Jan 22, 2021
  3. WAYNGames

    WAYNGames

    Joined:
    Mar 16, 2019
    Posts:
    938
    Or it's the other way around, there is a bad patching occurring and that piece of code from the native stream is no longer called :

    Code (CSharp):
    1.                     if (m_MinIndex == int.MinValue && m_MaxIndex == int.MinValue)
    2.                     {
    3.                         m_MinIndex = 0;
    4.                         m_MaxIndex = m_Writer.m_BlockStream->RangeCount - 1;
    5.                     }

    EDIT : I did not see any test in the entities or collection pacakge that covers both the native stream and ijobchunk at the same time. So this could have slip trhough in the 16 entities update. and possibly remains in the upcoming 17)
     
    Last edited: Jan 10, 2021
  4. desertGhost_

    desertGhost_

    Joined:
    Apr 12, 2018
    Posts:
    256
    If you add
    [NativeDisableParallelForRestriction]
    NativeStream.Writer in your job it works fine. It's just a safety system check that is reporting the error. This is still probably a bug in that I don't think the safety system should be reporting an error in this case.
     
  5. WAYNGames

    WAYNGames

    Joined:
    Mar 16, 2019
    Posts:
    938
    This will disable all safety checks for the container, I think my work around just "fix" the one bad check in my job but keep the other check just in case.
     
  6. WAYNGames

    WAYNGames

    Joined:
    Mar 16, 2019
    Posts:
    938
    Issue is still present in entities : 0.17.0-preview.41.
    Reported as :

    (Case 1308542) Native stream Bug in IJobChunk with entities 0.16.0-preview.21 and above