BlobArray error when accesses are done via a variable ?

Hi all !

When I access to a BlobArray in a for loop the result seems always wrong.

I wrote a simple test with a blobarray { 0,1,2 } and the first blobarray[0] return 8.

Anyone meets that before ?

I did bug report (1186219) but if you have a workaround because I’m block for now because of this :confused:

using System;
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using Unity.Collections;
using Unity.Entities;
using Unity.Jobs;
using UnityEngine;

namespace MyNamespace
{
public struct blolData
{
    public int valueInt;
    public RenderMode renderMode;
    public BlobArray<int> MyArray;
}

    public class Test
    {
        [Test]
        public void MyTest()
        {
            BlobAssetReference<blolData> blob;

            using (var builder = new BlobBuilder(Allocator.Temp))
            {
                ref var root = ref builder.ConstructRoot<blolData>();

                var targetBlobArray = builder.Allocate(ref root.MyArray, 3);

                for (var i = 0; i < targetBlobArray.Length; i++)
                    targetBlobArray[i] = i;

                root.renderMode       = RenderMode.ScreenSpaceOverlay;
                root.valueInt= 789;

                blob = builder.CreateBlobAssetReference<blolData>(Allocator.TempJob);
            }

            new DebugJob {blob = blob}.Schedule().Complete();
        }

        public struct DebugJob : IJob
        {
            /// <inheritdoc />
            public void Execute()
            {
                var array = blob.Value.MyArray;
                for (int i = 0; i < array.Length; i++)
                {
                    Assert.AreEqual(i , array[i]);
                }
            }

            public BlobAssetReference<blolData> blob;
        }

    }
}

4991216–487349–BlobArrayBug.zip (20 KB)

QA already confirms the bug, nice

https://issuetracker.unity3d.com/issues/entities-blobarray-access-returns-incorrect-value

1 Like

After watching this video, errors came from missing ref when I call my BlobArray :face_with_spiral_eyes:

2 Likes

Hmm that’s one big nasty gotcha. Scary thing is I think I’ve been using it without the refs, and my test suites did not catch anything.

Strangely for me if I access it with constant value ( myArray[0]n myArray[1] ) all work fine, maybe for that ?

As mentioned in the talk from yesterday, Unity is planning on making this a compile error :slight_smile:

1 Like