Merge pull request #75357 from Redwarx008/fix-Godot.Collections.Array.AddRange-index-out-of-bounds
C#: Fix `Array.AddRange` index out of bounds
This commit is contained in:
commit
dbf1a7277f
@ -554,6 +554,7 @@ namespace Godot.Collections
|
|||||||
// instead of growing it as we add items.
|
// instead of growing it as we add items.
|
||||||
if (collection.TryGetNonEnumeratedCount(out int count))
|
if (collection.TryGetNonEnumeratedCount(out int count))
|
||||||
{
|
{
|
||||||
|
int oldCount = Count;
|
||||||
Resize(Count + count);
|
Resize(Count + count);
|
||||||
|
|
||||||
using var enumerator = collection.GetEnumerator();
|
using var enumerator = collection.GetEnumerator();
|
||||||
@ -561,7 +562,7 @@ namespace Godot.Collections
|
|||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
enumerator.MoveNext();
|
enumerator.MoveNext();
|
||||||
this[count + i] = Variant.From(enumerator.Current);
|
this[oldCount + i] = Variant.From(enumerator.Current);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -1578,6 +1579,7 @@ namespace Godot.Collections
|
|||||||
// instead of growing it as we add items.
|
// instead of growing it as we add items.
|
||||||
if (collection.TryGetNonEnumeratedCount(out int count))
|
if (collection.TryGetNonEnumeratedCount(out int count))
|
||||||
{
|
{
|
||||||
|
int oldCount = Count;
|
||||||
Resize(Count + count);
|
Resize(Count + count);
|
||||||
|
|
||||||
using var enumerator = collection.GetEnumerator();
|
using var enumerator = collection.GetEnumerator();
|
||||||
@ -1585,7 +1587,7 @@ namespace Godot.Collections
|
|||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
enumerator.MoveNext();
|
enumerator.MoveNext();
|
||||||
this[count + i] = enumerator.Current;
|
this[oldCount + i] = enumerator.Current;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user