#[Resolved] How is this creating race condition??

1 messages · Page 1 of 1 (latest)

waxen lion
#

this doesnt sound right... it's as if state.CompleteDependency(); is not exactly waiting for the job to finish... this is the ISystem 's OnUpdate method that's calling a job that might take more than 50ms to complete

var enemyQuery = SystemAPI.QueryBuilder()
    .WithAll<LocalTransform>()
    .WithAll<UnitComponentData>()
    .WithAll<EnemyTag>()
    .Build();

var enemyLocalTransforms = enemyQuery.ToComponentDataArray<LocalTransform>( Allocator.TempJob );
var enemyUnits = enemyQuery.ToComponentDataArray<UnitComponentData>( Allocator.TempJob );

new AllyUnitMovementJob {
    deltaTime = SystemAPI.Time.DeltaTime,
    enemyTransforms = enemyLocalTransforms,
    enemyUnits = enemyUnits,
    enemyCount = enemyLocalTransforms.Length
}.ScheduleParallel( state.Dependency );

state.CompleteDependency();
enemyLocalTransforms.Dispose();
enemyUnits.Dispose();
#

and the error's stacktrace seems to be from the source gen side of the class

hearty herald
#

it's not waiting for AllyUnitMovementJob

#
    deltaTime = SystemAPI.Time.DeltaTime,
    enemyTransforms = enemyLocalTransforms,
    enemyUnits = enemyUnits,
    enemyCount = enemyLocalTransforms.Length
}.ScheduleParallel( state.Dependency );```
#

you pass in dependency but don't write it back to state.Dependency

waxen lion
hearty herald
#

for IJobEntity (assuming that's what you're using)

#

you either don't pass in a dependency and it's handled automatically

#

or if you do pass in a dependency you are saying you're managing this

#

and need to write it back as well

#

side note:
ToComponentDataListAsync is much better than ToComponentDataArray to avoid sync points

#

(though you have a sync point after this job anyway for some reason?)

#

(why is the complete required)

hearty herald
#

no

#

you are looking at ToComponentDataArrayAsync

#

note i said

#

ToComponentDataListAsync

waxen lion
#

ah, right

waxen lion
#

how do I write it back

#

I also searched the docs for 1.0.0

hearty herald
#

state.Dependency = new AllyUnitMovementJob {

waxen lion
#

ah , thanks! :D

#

how do you find that stuff though. they're not in the docs lol

hearty herald
#

i've been using entities for 5 years, before documentation existed

waxen lion
#

wow, that's from the very early preview versions

hearty herald
#

yeah like 2 weeks after it was first announced

#

back when it used dependency injection for components with [Inject]

waxen lion
hearty herald
#

i've seen some things mopCaffeine

waxen lion
#

so many trails of the old systems still show up in google as first results. when i accidentally open them, I realize how much progress ecs has made from then