From 493e39860dd5648fc0886b3e59772938158eedab Mon Sep 17 00:00:00 2001 From: Redwarx008 <50837890+Redwarx008@users.noreply.github.com> Date: Sun, 26 Mar 2023 21:14:08 +0800 Subject: C#: Fix Array.AddRange index out of bounds Fix Array.AddRange index out of bounds (cherry picked from commit eb1fb254a649efe128a3d993b7bd31486e9356e1) --- modules/mono/glue/GodotSharp/GodotSharp/Core/Array.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Array.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Array.cs index 8598c32760..5163ea5113 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Array.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Array.cs @@ -554,6 +554,7 @@ namespace Godot.Collections // instead of growing it as we add items. if (collection.TryGetNonEnumeratedCount(out int count)) { + int oldCount = Count; Resize(Count + count); using var enumerator = collection.GetEnumerator(); @@ -561,7 +562,7 @@ namespace Godot.Collections for (int i = 0; i < count; i++) { enumerator.MoveNext(); - this[count + i] = Variant.From(enumerator.Current); + this[oldCount + i] = Variant.From(enumerator.Current); } return; @@ -1578,6 +1579,7 @@ namespace Godot.Collections // instead of growing it as we add items. if (collection.TryGetNonEnumeratedCount(out int count)) { + int oldCount = Count; Resize(Count + count); using var enumerator = collection.GetEnumerator(); @@ -1585,7 +1587,7 @@ namespace Godot.Collections for (int i = 0; i < count; i++) { enumerator.MoveNext(); - this[count + i] = enumerator.Current; + this[oldCount + i] = enumerator.Current; } return; -- cgit v1.2.3