I already reported this behavior as a bug but might as well open a discussion here. Our jobified pathfinding code is suddenly not working when we upgraded to 2019.4.3 (and 2019.4.4) from 2019.4.1. Attached is the minimal project.
To replicate:
Open the project in Unity 2019.4.1.
Set Burst compilation as disabled (Jobs > Burst > Enable Compilation)
Run the scene Assets/AStarError/Scenes/AStarErrorTest.unity.
This should run fine without errors.
Open the project in Unity 2019.4.3.
Run the same scene.
There is now an error:
IndexOutOfRangeException: Index 0 is out of range of ‘0’ Length.
Unity.Collections.NativeArray1[T].FailOutOfRangeError (System.Int32 index) (at <a979f18d51af41179d12b797e8c5be14>:0) Unity.Collections.NativeArray1[T].CheckElementReadAccess (System.Int32 index) (at :0)
Unity.Collections.NativeArray1[T].get_Item (System.Int32 index) (at <a979f18d51af41179d12b797e8c5be14>:0) CommonEcs.AStarSearchParallelFor2[HeuristicCalculator,ReachabilityType].Execute (System.Int32 index) (at Assets/CommonEcs.AStar/Scripts/AStarSearchParallelFor.cs:41)
Unity.Jobs.IJobParallelForExtensions+ParallelForJobStruct`1[T].Execute (T& jobData, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) (at :0)
During debugging, I found that the NativeArray passed to AStarSearchParallelFor has a content but somehow those contents are lost when the job is executing. I don’t know what to look for as scheduling a job leads to native code outside of C#.
Have admittedly not looked at attached ZIP, but I suspect the cause is likely the usual one: a structural change due to an entitymanager command (see doc, e.g. AddComponent) between creating the entity array, and execution. Either within the same system, or by the next system when that next System is not waiting (Check dependencies). Such structural changes invalidate all Entity IDs.