Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

When a JobDebugger error is not an error, but a warning

Discussion in 'Data Oriented Technology Stack' started by sebas77, Feb 8, 2020.

  1. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,220
    Code (CSharp):
    1.  
    2. foreach (var group in GameGroups.DOOFUSES.Groups)
    3. {
    4.     var collection = entitiesDB.QueryEntities<PositionEntityStruct>(group);
    5.     if (collection.length == 0) continue;
    6.     var entityCollection = collection.GetNativeEnumerator<PositionEntityStruct>();
    7.     var job = Entities.ForEach((ref Translation translation) =>
    8.                                {
    9.                                    ref readonly var positionEntityStruct =
    10.                                        ref entityCollection.threadSafeNext.position;
    11.                                    translation.Value =
    12.                                        new float3(positionEntityStruct.x, positionEntityStruct.y,
    13.                                                   positionEntityStruct.z);
    14.                                }).WithBurst()
    15.                       .WithSharedComponentFilter(new UECSSveltoGroupID((uint) @group)).Schedule(inputDeps);
    16.     combinedDependencies = JobHandle.CombineDependencies(combinedDependencies,
    17.                                                          new DisposeJob<EntityCollection<
    18.                                                                  PositionEntityStruct>.EntityNativeIterator<
    19.                                                                  PositionEntityStruct>>(entityCollection)
    20.                                                             .Schedule(job));
    21. }
    22.  
    I get:

    Code (CSharp):
    1. InvalidOperationException: The previously scheduled job RenderingDataSynchronizationEngine:<>c__DisplayClass_OnUpdate_LambdaJob0 writes to the NativeArray <>c__DisplayClass_OnUpdate_LambdaJob0.Data._lambdaParameterValueProviders.forParameter_translation._type. You are trying to schedule a new job RenderingDataSynchronizationEngine:<>c__DisplayClass_OnUpdate_LambdaJob0, which writes to the same NativeArray (via <>c__DisplayClass_OnUpdate_LambdaJob0.Data._lambdaParameterValueProviders.forParameter_translation._type). To guarantee safe
    2.  
    While it's true that I am scheduling the jobs on purpose to run in parallel and not in serial, If I am not wrong or I misunderstood the code, the filter should guarantee that I am writing in separate entity arrays. I guess the JobDebugger cannot know that (could it know?). Thoughts?
     
  2. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,509
    It knows only down to typing and not exactly which chunks, if you know your filter guarantees it then I guess you should WithNativeDisableContainerSafetyRestriction
     
    sebas77 likes this.
  3. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,220
    Thanks I was looking exactly for this answer
     
  4. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,220
    WithNativeDisableContainerSafetyRestriction needs a captured variable as parameter, it doesn't disable the check for the whole foreach. Thoughts?
     
  5. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,509
    How about use CDFE of Translation instead so that became an imported container?
     
  6. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,220
    I guess at that point I may even just not use foreach and make a custom IJobParallel
     
unityunity