Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved UnsafeList Length always 0

Discussion in 'Burst' started by HellGate94, Apr 14, 2022.

  1. HellGate94

    HellGate94

    Joined:
    Sep 21, 2017
    Posts:
    132
    After updating to Burst 1.6.5, Jobs 0.50.0-pre8, Collections 1.2.3 every `UnsafeList<T>` has a length of 0 after allocating.

    Code (CSharp):
    1.     _voxelData = new UnsafeList<T>(length, allocator, options);
    2.     Debug.Log($"Trying to allocate {length} items. Items allocated: {_voxelData.Length} and IsCreated is {_voxelData.IsCreated}");
    shows `Trying to allocate 32768 items. Items allocated: 0 and IsCreated is True`
     
  2. Carpet_Head

    Carpet_Head

    Joined:
    Nov 27, 2014
    Posts:
    254
    you're setting the initial capacity, not the length. you need to do
    _voxelData.Length = length;
     
    HellGate94 likes this.
  3. HellGate94

    HellGate94

    Joined:
    Sep 21, 2017
    Posts:
    132
    you are right. seems like the previous version i used did no bounds checks? also kinda forgot that it is the capacity since i just use it as an array

    also the fact that its called Length and not Count like in .Net made me not think of it