Search Unity

2021.2.8f1 broke AsDeferredJobArray and deferred jobs

Discussion in 'Entity Component System' started by LennartJohansen, Jan 16, 2022.

  1. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    In the changelog of Unity 2021.2.8f1 there was a fix for an issue with GetSubArray.

    This seems to have broken passing NativeLists to IJobParallelForDefer jobs.

    Normally the scheduler would update the pointer to the NativeArray returned by list.AsDeferredJobArray() to the current size of the NativeList when starting the job. After the "fix" it gives an access violation.
    • Kernel: Fixed an issue where low bit set in NativeArray buffer pointer assumes NativeArray is created by NativeList.AsDeferredJobArray, which is not always the case. In some cases NativeArray can be created by NativeArray.GetSubArray, where pointer would have lowest bit set for odd byte aligned offset. (1294627)
    It looks like the same "fix" will enter Unity 2022.2.0a1 and Unity 2020.3.26f1 breaking functionality there also.

    Anyone know of a workaround to fix this issue?
     
    mars2nico likes this.
  2. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    As a temporary fix you can pass the NativeList to the job an disable the parallell min/max restriction.

    [NativeDisableParallelForRestriction]
    public NativeList<int> yourNativeList;


    You should then be able to read/write the Items in the NativeList the same way you would the deferred NativeArray.
     
  3. Srokaaa

    Srokaaa

    Joined:
    Sep 18, 2018
    Posts:
    169
    Yep, can confirm. Unity Physics is broken on 2020.3.26f1. Can't recall the exact stacktrace now
     
  4. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    In the collections package, change AsDeferredJobArray allocator to Invalid from None

    -edit-

    For anyone not sure how to do this

    - go into YOURPROJECTLibrary/PackageCache/
    - copy com.unity.collections@0.15.0-preview.21 into YOURPROJECT/Packages/
    - open com.unity.collections@0.15.0-preview.21\Unity.Collections\NativeList.cs
    - change line 599 from Allocator.None to Allocator.Invalid
     
    Last edited: Jan 19, 2022
  5. eggsamurai

    eggsamurai

    Joined:
    Oct 10, 2015
    Posts:
    115
    I think the bug is caused by IL2CPP. Really suffered from .2.8 and IL2CPP
     
  6. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    it happens on Mono also
     
  7. MartinIsla

    MartinIsla

    Joined:
    Sep 18, 2013
    Posts:
    104
    I love you (please don't tell my boyfriend)
     
  8. sheikhg1900

    sheikhg1900

    Joined:
    Sep 13, 2021
    Posts:
    8
    Great. It resolved it.
     
    Zagule likes this.
  9. Goularou

    Goularou

    Joined:
    Oct 19, 2018
    Posts:
    54
    Wow: very impressive technically and definitely working. I spent days trying to fix my mistakes on compound colliders while it was just this bug... Thank You so much.:):):)

    EDIT: I do regret that Unity does not have a template ECS project for testing prior to releasing a LTS, if they would have tried any basic project, they would have found that bug as here it is a base part (body) of a base package (physcis).
     
    Last edited: Feb 4, 2022
    heu3becteh and Zagule like this.
  10. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    987
    Encountered this bug in 2020.3.27. Thanks @tertle!
     
  11. Anthiese

    Anthiese

    Joined:
    Oct 13, 2013
    Posts:
    73
    DevViktoria likes this.
  12. carlosfritz

    carlosfritz

    Joined:
    Feb 17, 2018
    Posts:
    32
    Last edited: Feb 2, 2022
    lclemens likes this.
  13. brklipel

    brklipel

    Joined:
    Mar 5, 2019
    Posts:
    2
    lclemens likes this.
  14. heu3becteh

    heu3becteh

    Joined:
    Aug 6, 2020
    Posts:
    25
    I did use Unity 2019 until now, because 2020 LTS is utterly broken: you can not even put a sphere on a plane (with ECS) in a brand new project without bug. It is strange how could something like that happen and even stay like that for a while...
    I appretiate the fix by @tertle, it does help... But I hope it would be fixed officially.
     
  15. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    It'll (likely) be fixed in collections 1.2 except this will not support the current version of entities so we'll have to wait till 0.50 is released before it's fixable with entities without a custom package.
     
  16. unity_IeXpByheuIMatQ

    unity_IeXpByheuIMatQ

    Joined:
    Jan 23, 2022
    Posts:
    1
    thank you! @tertle
    but the cast ray function is still having similar error text after fixed
    anyone have the same issue?
     
  17. MicCode

    MicCode

    Joined:
    Nov 19, 2018
    Posts:
    59

    Great fix, I'm using entities in 2021.2.10 now, added

    Packages/com.unity.collections@0.15.0-preview.21/

    to .gitignore to avoid committing a bunch of stuff that is not needed after the bug is fixed
     
    kduxwr likes this.
  18. CaptainGaryPecker

    CaptainGaryPecker

    Joined:
    Nov 4, 2020
    Posts:
    1
    Thanks a lot ^^
    You're amazing!
     
  19. shamsfk

    shamsfk

    Joined:
    Nov 21, 2014
    Posts:
    307
    Unity detected that my immutable asset was changed and invalidated cache effectively removing the fix. is there a way to make it stop doing that?
     
  20. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    shamsfk and Anthiese like this.
  21. shamsfk

    shamsfk

    Joined:
    Nov 21, 2014
    Posts:
    307
  22. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    987
    Damn. So the hack stays then.
     
    DevViktoria likes this.
  23. yunpu1004

    yunpu1004

    Joined:
    Mar 8, 2020
    Posts:
    2
    Thank you sir, you cured my cancer. Now I am very healthy!!!
     
  24. Anthiese

    Anthiese

    Joined:
    Oct 13, 2013
    Posts:
    73
    Rejoice. Entities 0.50 has Collections dependency 1.2.3-pre.1 and 1.2.1 had implemented tertle’s fix.
     
    lclemens and EternalAmbiguity like this.