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); 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;