2021.2.8f1 broke AsDeferredJobArray and deferred jobs

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?

1 Like

As a temporary fix you can pass the NativeList to the job an disable the parallell min/max restriction.

[NativeDisableParallelForRestriction]
public NativeList yourNativeList;

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

Yep, can confirm. Unity Physics is broken on 2020.3.26f1. Can’t recall the exact stacktrace now

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
42 Likes

I think the bug is caused by IL2CPP. Really suffered from .2.8 and IL2CPP

it happens on Mono also

I love you (please don’t tell my boyfriend)

4 Likes

Great. It resolved it.

1 Like

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.:):):slight_smile:

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).

2 Likes

Encountered this bug in 2020.3.27. Thanks @tertle !

Evidently there’s an issue for this and there’s a fix coming

1 Like

Thank you, @tertle !

1 Like

Thank you @tertle !

1 Like

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.

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.

thank you! @tertle
but the cast ray function is still having similar error text after fixed
anyone have the same issue?

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

1 Like

Thanks a lot ^^
You’re amazing!

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?

I provided instructions above : https://discussions.unity.com/t/868414/4

2 Likes