From 0affaf50994e572e949574eb487b2c8cd0615d67 Mon Sep 17 00:00:00 2001 From: Roycon Date: Mon, 20 Nov 2023 16:49:28 +0000 Subject: [PATCH 1/2] Fixed again --- Arch.LowLevel/Jagged/SparseJaggedArray.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Arch.LowLevel/Jagged/SparseJaggedArray.cs b/Arch.LowLevel/Jagged/SparseJaggedArray.cs index bffe1cb..7cd6236 100644 --- a/Arch.LowLevel/Jagged/SparseJaggedArray.cs +++ b/Arch.LowLevel/Jagged/SparseJaggedArray.cs @@ -202,6 +202,11 @@ public void Add(int index, in T item) { IndexToSlot(index, out var bucketIndex, out var itemIndex); + if (bucketIndex >= _bucketArray.Length) + { + EnsureCapacity(index); + } + ref var bucket = ref _bucketArray[bucketIndex]; bucket.EnsureCapacity(); bucket[itemIndex] = item; From 21e2b1c9650ae0b950eb26f9458842a37d506848 Mon Sep 17 00:00:00 2001 From: Roycon Date: Mon, 20 Nov 2023 17:13:29 +0000 Subject: [PATCH 2/2] Another capacity check (that was missing?) --- Arch.LowLevel/Jagged/JaggedArray.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Arch.LowLevel/Jagged/JaggedArray.cs b/Arch.LowLevel/Jagged/JaggedArray.cs index 4ab4194..982d401 100644 --- a/Arch.LowLevel/Jagged/JaggedArray.cs +++ b/Arch.LowLevel/Jagged/JaggedArray.cs @@ -212,6 +212,12 @@ public bool TryGetValue(int index, out T value) value = _filler; return false; } + + if (index >= Capacity) + { + value = _filler; + return false; + } IndexToSlot(index, out var bucketIndex, out var itemIndex);