public void DisposeJobWithMissingDependencyThrows()
    {
        var list = new NativeList <int> (Allocator.Persistent);
        var deps = new NativeListAddJob(list).Schedule();

        Assert.Throws <InvalidOperationException> (() => { list.Dispose(default(JobHandle)); });
        deps.Complete();
        list.Dispose();
    }
Ejemplo n.º 2
0
    public void NativeList_DisposeJob()
    {
        var list = new NativeList <int>(Allocator.Persistent);
        var deps = new NativeListAddJob(list).Schedule();

        deps = list.Dispose(deps);
        Assert.IsFalse(list.IsCreated);
        deps.Complete();
    }
Ejemplo n.º 3
0
    public void ScheduleDerivedArrayExceptions()
    {
        var list = new NativeList <int> (1, Allocator.Persistent);

        var addListJobHandle = new NativeListAddJob(list).Schedule();

        Assert.Throws <System.InvalidOperationException> (() => { NativeArray <int> array = list; });

        addListJobHandle.Complete();
        list.Dispose();
    }
Ejemplo n.º 4
0
    public void ScheduleDerivedArrayExceptions()
    {
        var list = new NativeList <int>(1, Allocator.Persistent);

        var addListJobHandle = new NativeListAddJob(list).Schedule();

#pragma warning disable 0219 // assigned but its value is never used
        Assert.Throws <InvalidOperationException>(() => { NativeArray <int> array = list; });
#pragma warning restore 0219

        addListJobHandle.Complete();
        list.Dispose();
    }
Ejemplo n.º 5
0
    public void AccessBefore()
    {
        var list = new NativeList <int>(Allocator.TempJob);

        var jobHandle = new NativeListAddJob(list).Schedule();

        Assert.Throws <InvalidOperationException>(() =>
        {
            list.AsArray();
        });

        jobHandle.Complete();
        list.Dispose();
    }
Ejemplo n.º 6
0
    public void ScheduleDerivedArrayExceptions2()
    {
        var list = new NativeList <int>(1, Allocator.Persistent);
        NativeArray <int> array = list;

        var addListJobHandle = new NativeListAddJob(list).Schedule();

        // The array previously cast should become invalid
        // as soon as the job is scheduled, since we can't predict if an element will be added or not
        Assert.Throws <InvalidOperationException>(() => { new NativeArrayTest(array).Schedule(); });

        addListJobHandle.Complete();
        list.Dispose();
    }
Ejemplo n.º 7
0
    public void AccessAfter()
    {
        var list      = new NativeList <int>(Allocator.TempJob);
        var array     = list.AsArray();
        var jobHandle = new NativeListAddJob(list).Schedule();

        Assert.Throws <System.InvalidOperationException>(() =>
        {
            new NativeArrayTest(array).Schedule(jobHandle);
        });
        jobHandle.Complete();

        list.Dispose();
    }
Ejemplo n.º 8
0
    public void AddElementToListFromJobInvalidatesArray()
    {
        var list = new NativeList <int>(Allocator.TempJob);

        list.Add(0);

        NativeArray <int> arrayBeforeSchedule = list;

        Assert.AreEqual(list.Length, 1);

        var jobData = new NativeListAddJob(list);
        var job     = jobData.Schedule();

#if UNITY_2020_2_OR_NEWER
        Assert.Throws <ObjectDisposedException>(
#else
        Assert.Throws <InvalidOperationException>(
#endif
            () => { Debug.Log(arrayBeforeSchedule[0]); });
        Assert.Throws <InvalidOperationException>(() => { NativeArray <int> array = list; Debug.Log(array.Length); });
        Assert.Throws <InvalidOperationException>(() => { Debug.Log(list.Capacity); });
        Assert.Throws <InvalidOperationException>(() => { list.Dispose(); });
        Assert.Throws <InvalidOperationException>(() => { Debug.Log(list[0]); });

        job.Complete();

        Assert.AreEqual(1, arrayBeforeSchedule.Length);
#if UNITY_2020_2_OR_NEWER
        Assert.Throws <ObjectDisposedException>(
#else
        Assert.Throws <InvalidOperationException>(
#endif
            () => { Debug.Log(arrayBeforeSchedule[0]); });

        Assert.AreEqual(2, list.Length);
        Assert.AreEqual(0, list[0]);
        Assert.AreEqual(1, list[1]);

        NativeArray <int> arrayAfter = list;
        Assert.AreEqual(2, arrayAfter.Length);
        Assert.AreEqual(0, arrayAfter[0]);
        Assert.AreEqual(1, arrayAfter[1]);

        list.Dispose();
    }