ScheduleParallel() crashes computer. Schedule() does not.

Executing SystemBase code:

[DisableAutoCreation]
public class CrashComputer : SystemBase
{
    private NativeArray<UnsafeList<v256>> _deltas, _inventories;

    public JobHandle SystemHandle;

    protected override void OnCreate()
    {
        _deltas = new NativeArray<UnsafeList<v256>>(2400, Allocator.Persistent,
            NativeArrayOptions.UninitializedMemory);
        _inventories = new NativeArray<UnsafeList<v256>>(_deltas.Length, Allocator.Persistent,
            NativeArrayOptions.UninitializedMemory);

        var random = new Random(54321);

        const int size = 1000;
        for (var index = 0; index < _deltas.Length; index++)
        {
            var list = new UnsafeList<v256>(size, Allocator.Persistent);
            _inventories[index] = new UnsafeList<v256>(size, Allocator.Persistent, NativeArrayOptions.ClearMemory);
            for (var pop = 0; pop < size; pop++)
            {
                var target = new v256((sbyte) random.NextInt(-1, 2), (sbyte) random.NextInt(-1, 2),
                    (sbyte) random.NextInt(-1, 2), (sbyte) random.NextInt(-1, 2), (sbyte) random.NextInt(-1, 2),
                    (sbyte) random.NextInt(-1, 2), (sbyte) random.NextInt(-1, 2), (sbyte) random.NextInt(-1, 2),
                    (sbyte) random.NextInt(-1, 2), (sbyte) random.NextInt(-1, 2), (sbyte) random.NextInt(-1, 2),
                    (sbyte) random.NextInt(-1, 2), (sbyte) random.NextInt(-1, 2), (sbyte) random.NextInt(-1, 2),
                    (sbyte) random.NextInt(-1, 2), (sbyte) random.NextInt(-1, 2), (sbyte) random.NextInt(-1, 2),
                    (sbyte) random.NextInt(-1, 2), (sbyte) random.NextInt(-1, 2), (sbyte) random.NextInt(-1, 2),
                    (sbyte) random.NextInt(-1, 2), (sbyte) random.NextInt(-1, 2), (sbyte) random.NextInt(-1, 2),
                    (sbyte) random.NextInt(-1, 2), (sbyte) random.NextInt(-1, 2), (sbyte) random.NextInt(-1, 2),
                    (sbyte) random.NextInt(-1, 2), (sbyte) random.NextInt(-1, 2), (sbyte) random.NextInt(-1, 2),
                    (sbyte) random.NextInt(-1, 2), (sbyte) random.NextInt(-1, 2), (sbyte) random.NextInt(-1, 2)
);
                list.Add(target);
            }

            _deltas[index] = list;
        }
    }

    protected override void OnUpdate()
    {
        // ------ WARNING ------ WILL CRASH COMPUTER ------
        Dependency = new TestJob
        {
            Deltas = _deltas,
            Inventories = _inventories
        }.ScheduleParallel(_deltas.Length, 1, default);

        // THIS DOES NOT CRASH COMPUTER (executes as expected)
        // Dependency = new TestJob
        // {
        //     Deltas = _deltas,
        //     Inventories = _inventories
        // }.Schedule(_deltas.Length, default);

        // Note, setting the dependency parameter of both jobs to Dependency
        // seems to prevent the crash? Maybe. It goes from crash 100% to crash
        // maybe 25% for parallel scheduling and restarting Unity after every run.

        // Singlethreaded Schedule() works with default
        // or Dependency as expected with no crashing.

        SystemHandle = Dependency;
    }

    protected override void OnDestroy()
    {
        Dependency.Complete();

        foreach (var delta in _deltas)
            delta.Dispose();
        _deltas.Dispose();

        foreach (var inventory in _inventories)
            inventory.Dispose();
        _inventories.Dispose();
    }

    [BurstCompile]
    private unsafe struct TestJob : IJobFor
    {
        [ReadOnly] public NativeArray<UnsafeList<v256>> Deltas;

        public NativeArray<UnsafeList<v256>> Inventories;

        public void Execute(int index)
        {
            var deltaPtr = Deltas[index].Ptr;
            var inventoryPtr = Inventories[index].Ptr;

            RegularAddition((sbyte*) deltaPtr, (sbyte*) inventoryPtr);
        }

        [MethodImpl(MethodImplOptions.NoInlining)]
        private static void RegularAddition([NoAlias] sbyte* deltasPtr, [NoAlias] sbyte* inventoriesPtr)
        {
            for (var index = 0; index < 1000; index++)
            for (var inside = 0; inside < 32; inside++)
                inventoriesPtr[index * 32 + inside] += deltasPtr[index * 32 + inside];
        }
    }
}

Code executing on player loop:

public class WorldUpdateManager : SystemBase
{
    private World _world;

    private CrashComputer _crashComputer;

    protected override void OnStartRunning()
    {
        _world = new World("Test World");

        var simulationGroup = _world.CreateSystem<SimulationSystemGroup>();

        _crashComputer = _world.CreateSystem<CrashComputer>();
        simulationGroup.AddSystemToUpdateList(_crashComputer);
    }

    protected override void OnUpdate()
    {
        if (!_crashComputer.SystemHandle.IsCompleted)
            return;

        _world.Update();
    }
}

There is no error message. Computer BSOD requiring me to restart.

Note, this is a standalone job copy of a DOTS Entities version doing the exact same code, which also crashes when using ScheduleParallel().

All instances of ScheduleParallel results in crashes. Regardless of job type. Tested with IJobFor (found here), IJobParallelFor, IJobEntityBatch, and IJobChunk.
Code executed on Unity 2022.1 Beta 2. Entities 0.17. Burst 1.7.0 pre-1.

Tried the same setup locally, could not get it to fail nor crash the computer. I tried Burst 1.6.3, 1.7.0-pre.1, and our latest internal Burst, all worked.

If the issue still persists can you submit an actual ticket with a repro for this please?

1 Like

Damn, wish just putting the code here would allow for reproducing. Now I have to go the long way…

Just saw the post about y’all going on vacation. Hope y’all have a good time.

Odd, making a new project and pasting in the code doesnt crash my computer… Well I do have a lot of other stuff going on in the other project, probably a memory overflow or something.

Edit: Got it to crash my computer in a empty project.

Key thing: Turn off burst. I dont know if it’s relevant for your team now but since Burst cant exist without the job system (well until ISystemBase comes along), I’ll leave the ticket here.

(Case 1390060) ScheduleParallel() crashes computer. Schedule() does not.