Search Unity

BlobArray error when accesses are done via a variable ?

Discussion in 'Entity Component System' started by Sylmerria, Sep 23, 2019.

  1. Sylmerria

    Sylmerria

    Joined:
    Jul 2, 2012
    Posts:
    369
    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 :/

    Code (CSharp):
    1. using System;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using NUnit.Framework;
    5. using Unity.Collections;
    6. using Unity.Entities;
    7. using Unity.Jobs;
    8. using UnityEngine;
    9.  
    10. namespace MyNamespace
    11. {
    12. public struct blolData
    13. {
    14.     public int valueInt;
    15.     public RenderMode renderMode;
    16.     public BlobArray<int> MyArray;
    17. }
    18.  
    19.     public class Test
    20.     {
    21.         [Test]
    22.         public void MyTest()
    23.         {
    24.             BlobAssetReference<blolData> blob;
    25.  
    26.             using (var builder = new BlobBuilder(Allocator.Temp))
    27.             {
    28.                 ref var root = ref builder.ConstructRoot<blolData>();
    29.  
    30.                 var targetBlobArray = builder.Allocate(ref root.MyArray, 3);
    31.  
    32.                 for (var i = 0; i < targetBlobArray.Length; i++)
    33.                     targetBlobArray[i] = i;
    34.  
    35.                 root.renderMode       = RenderMode.ScreenSpaceOverlay;
    36.                 root.valueInt= 789;
    37.  
    38.                 blob = builder.CreateBlobAssetReference<blolData>(Allocator.TempJob);
    39.             }
    40.  
    41.             new DebugJob {blob = blob}.Schedule().Complete();
    42.         }
    43.  
    44.         public struct DebugJob : IJob
    45.         {
    46.             /// <inheritdoc />
    47.             public void Execute()
    48.             {
    49.                 var array = blob.Value.MyArray;
    50.                 for (int i = 0; i < array.Length; i++)
    51.                 {
    52.                     Assert.AreEqual(i , array[i]);
    53.                 }
    54.             }
    55.  
    56.             public BlobAssetReference<blolData> blob;
    57.         }
    58.  
    59.     }
    60. }
     

    Attached Files:

  2. Sylmerria

    Sylmerria

    Joined:
    Jul 2, 2012
    Posts:
    369
  3. Sylmerria

    Sylmerria

    Joined:
    Jul 2, 2012
    Posts:
    369
    After watching this video, errors came from missing ref when I call my BlobArray :confused:
     
    Singtaa and siggigg like this.
  4. Singtaa

    Singtaa

    Joined:
    Dec 14, 2010
    Posts:
    492
    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.
     
  5. Sylmerria

    Sylmerria

    Joined:
    Jul 2, 2012
    Posts:
    369
    Strangely for me if I access it with constant value ( myArray[0]n myArray[1] ) all work fine, maybe for that ?
     
  6. siggigg

    siggigg

    Joined:
    Apr 11, 2018
    Posts:
    247
    As mentioned in the talk from yesterday, Unity is planning on making this a compile error :)
     
    Sylmerria likes this.