You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Godot Engine v4.0.2.stable.official.7a0977ce2
OpenGL API 3.3.0 - Build 21.20.16.4821 - Compatibility - Using Device: Intel - Intel(R) HD Graphics 520
System information
Windows 10
Issue description
Using remove_at method of Array throws out of bounds errors even if the size allows for specified index
Using remove_at with negative index:
E 0:00:08:0882 Enemy.gd:163 @ _on_Player_move(): Index p_index = -1 is out of bounds (size() = 3).
<C++ Source> ./core/templates/cowdata.h:164 @ remove_at()
Using positive index:
E 0:00:11:0721 Enemy.gd:163 @ _on_Player_move(): Index p_index = 4 is out of bounds (size() = 4).
<C++ Source> ./core/templates/cowdata.h:164 @ remove_at()
However, if using Array.erase(Array[-1]) no errors are shown.
Steps to reproduce
if keyboard button is pressed:
var a: Array = []
a.resize(10)
a.fill(1)
a.remove_at(-1)
Minimal reproduction project (MRP)
Not required
The text was updated successfully, but these errors were encountered:
Hi, for the remove_at() function in the documentation it states that negative indices don't work and that you would need to do arr.remove_at(arr.size() - (i + 1)). Similarly for removing at the size, array indices start counting at 0, so the final index would be a 3 not a 4 for size() = 4.
Hello! As the previous comment suggested, you cannot use negative indexes. It seems like you tried to pop back, i'd suggest you take a look at this method Array.pop_back() -> Variant
Tested versions
Godot Engine v4.0.2.stable.official.7a0977ce2
OpenGL API 3.3.0 - Build 21.20.16.4821 - Compatibility - Using Device: Intel - Intel(R) HD Graphics 520
System information
Windows 10
Issue description
Using
remove_at
method ofArray
throws out of bounds errors even if the size allows for specified indexUsing
remove_at
with negative index:Using positive index:
However, if using
Array.erase(Array[-1])
no errors are shown.Steps to reproduce
if keyboard button is pressed:
Minimal reproduction project (MRP)
Not required
The text was updated successfully, but these errors were encountered: