#Scheduling jobs from monobehaviour - previously scheduled job writes to collection errors

1 messages · Page 1 of 1 (latest)

brazen canopy
#

I cant get this to schedule using the final jobhandle(handle3), only when I force complete each job individually. I feel like im missing something super basic here? cellHashMap is a NativeHashmap

Each time it spits out InvalidOperationException: The previously scheduled job CollapseRandomCellJob writes to the Unity.Collections.NativeHashMap2[Unity.Mathematics.int3,Junk.Yard.CellData] CollapseRandomCellJob.HashMap. You must call JobHandle.Complete() on the job CollapseRandomCellJob, before you can read from the Unity.Collections.NativeHashMap 2[Unity.Mathematics.int3,Junk.Yard.CellData] safely.

var handle1 = new SetupJob {
   HashMap   = cellHashMap,
   CellScale = CellScale,
   GridSize  = GridSize,
   Position  = transform.position,
}.Schedule();
                
 var handle2 = new CollapseRandomCellJob {
   GridSize = GridSize,
   Seed        = seed,
   Iterations  = iterations,
   HashMap    = cellHashMap
 }.Schedule(handle1);

var handle3 = new CollapseAndSolveAllJob{
   Iterations = iterationMultiplier * cellHashMap.Count,
   HashMap   = cellHashMap,
}.ScheduleParallel(cellHashMap.Count, 4, handle2);
handle3.Complete();
errant shoal
#

How can you count a hash map in job 3

#

Until it's filled in previous jobs

brazen canopy
#

oh? im initializing it like
var cellHashMap = new NativeHashMap<int3, CellData>(cellCount, Allocator.TempJob);

errant shoal
#

Yeah but count will be 0

#

Because no elements added

#

And you can't read count while it's being used in other jobs

#

All you're doing is setting capacity

brazen canopy
#

thanks, that does clear things up

#

@errant shoal saved my sanity 😀