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.