#Unexpected clear

1 messages · Page 1 of 1 (latest)

left latch
#

Unity 2022.2.18 & 2022.2.19
Test code:

public unsafe class TestCompress : MonoBehaviour
{
    private const string DllName = "liblz4";

    [DllImport(DllName, EntryPoint = "LZ4_compressBound")]
    private static extern int CompressBoundLZ4(int srcSize);

    [DllImport(DllName, EntryPoint = "LZ4_compress_default")]
    private static extern int CompressLZ4(byte* src, byte* dst, int srcSize, int dstCapacity);

    [DllImport(DllName, EntryPoint = "LZ4_decompress_safe")]
    private static extern int DecompressLZ4(byte* src, byte* dst, int compressedSize, int dstCapacity);

    public void Awake()
    {
        var payload = new NativeArray<byte>(1234, Allocator.Temp);
        for (var i = 0; i < payload.Length; i++)
        {
            payload[i] = (byte)(i % byte.MaxValue);
        }

        var boundedSize = CompressBoundLZ4(payload.Length);
        var compressed = new NativeArray<byte>(boundedSize, Allocator.Temp);
        var compressedSize = CompressLZ4((byte*)payload.GetUnsafePtr(), (byte*)compressed.GetUnsafePtr(), payload.Length, boundedSize);

        var decompressed = new NativeArray<byte>(1234, Allocator.Temp);
        var result = DecompressLZ4((byte*)compressed.GetUnsafePtr(), (byte*)decompressed.GetUnsafePtr(), compressedSize, decompressed.Length);

        if (result > 0)
        {
            Debug.Log("Success");
        }
        else
        {
            Debug.LogError("Fail");
        }
    }
}```
#

This is the liblz4 i'm using, it's from entities 0.51. As far as i can tell it's the exact same one that ships with entities 1.0.8.
In editor historically I've just used one that ships with entities and use this one at runtime to avoid conflicts (since entities is marked editor only).
I thought maybe there was a conflict so I forked entities package and removed the liblz4 that was included and same result.
Previously this has worked in every entities version since at least 0.17.

#

I'm struggling to even think what in entities or it's dependencies that could somehow break using this dll.

#

OK now removing entities, adding entities back and it's passing 😫

#

OK I was slightly wrong
It seems to be related to NativeList vs NativeArray somehow

#
    private static void Array(int boundedSize, NativeArray<byte> payload, NativeArray<byte> decompressed)
    {
        var compressed = new NativeArray<byte>(boundedSize, Allocator.Temp);
        var compressedSize = CompressLZ4((byte*)payload.GetUnsafePtr(), (byte*)compressed.GetUnsafePtr(), payload.Length, boundedSize);
        var result = DecompressLZ4((byte*)compressed.GetUnsafePtr(), (byte*)decompressed.GetUnsafePtr(), compressedSize, decompressed.Length);
        if (result > 0) Debug.Log("Array Success");
        else Debug.LogError("Array Fail");
    }

    private static void List(int boundedSize, NativeArray<byte> payload, NativeArray<byte> decompressed)
    {
        var compressed = new NativeList<byte>(boundedSize, Allocator.Temp);
        compressed.Length = CompressLZ4((byte*)payload.GetUnsafePtr(), (byte*)compressed.GetUnsafePtr(), payload.Length, boundedSize);
        var result = DecompressLZ4((byte*)compressed.GetUnsafePtr(), (byte*)decompressed.GetUnsafePtr(), compressed.Length, decompressed.Length);
        if (result > 0) Debug.Log("List Success");
        else Debug.LogError("List Fail");
    }```
#

order isn't relevant

#
    private static void UnsafeList(int boundedSize, NativeArray<byte> payload, NativeArray<byte> decompressed)
    {
        var compressedList = new UnsafeList<byte>(boundedSize, Allocator.Temp);
        compressedList.Length = CompressLZ4((byte*)payload.GetUnsafePtr(), (byte*)compressedList.Ptr, payload.Length, boundedSize);
        var result = DecompressLZ4((byte*)compressedList.Ptr, (byte*)decompressed.GetUnsafePtr(), compressedList.Length, decompressed.Length);
        if (result > 0) Debug.Log("UnsafeList Success");
        else Debug.LogError("UnsafeList Fail");
    }```
#

UnsafeList works fine

#

i need to go diff native list

#

i feel like i must be doing something silly because in my above code because this is not making sense to me

#
        {
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            readonly get
            {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
                AtomicSafetyHandle.CheckReadAndThrow(m_Safety);
#endif
                return CollectionHelper.AssumePositive(m_ListData->Length);
            }

            set
            {
                m_ListData->Resize(value, NativeArrayOptions.ClearMemory);
            }
        }```
#

m_ListData->Resize(value, NativeArrayOptions.ClearMemory);

#

did this always clear memory on resize

#

it did at least recently.... how did this ever work