Search Unity

Question [Job system] can't read/access all elemnts of an [readonly] array in IJobParallelForTransform

Discussion in 'C# Job System' started by unity_ufo7n3HR9ORliw, Apr 3, 2021.

  1. unity_ufo7n3HR9ORliw

    unity_ufo7n3HR9ORliw

    Joined:
    Jul 22, 2019
    Posts:
    2
    Hi.
    I have been struggling with this issue for several days can any one help me with it?
    the problem is that I want to access to the whole data of an specific array within my job, I have read that with ReadOnly attribute you can do it, yes that's true, but It is only working on IJobParallelFor.
    It is not working on IJobParallelForTransform interface!!

    I have write below code and it is giving me exception.


    mono update:
    void Update()
    {

    TransformAccessArray transAccArr = new TransformAccessArray(characters);
    var job = new JobTest();
    NativeArray<int> indexes = new NativeArray<int>(currentIndex,Allocator.TempJob);
    job.intArray = indexes;
    // Schedule the job
    int a = currentIndex.Length;
    JobHandle handle = job.Schedule(transAccArr);
    handle.Complete();

    indexes.Dispose();
    transAccArr.Dispose();
    }

    public struct JobTest: IJobParallelForTransform
    {
    [ReadOnly] public NativeArray<int> intArray;



    public void Execute(int index, TransformAccess transform)
    {
    var tt = intArray[2];//if I remove this line no exception will be thrown
    var t = transform.localScale;
    t *= 0.9f;
    transform.localScale = t;

    }
    }

    Exception:
    IndexOutOfRangeException: Index 2 is out of restricted IJobParallelFor range [1...1] in ReadWriteBuffer.
    ReadWriteBuffers are restricted to only read & write the element at the job index. You can use double buffering strategies to avoid race conditions due to reading & writing in parallel to the same elements from a job.
     
    Last edited: Apr 3, 2021