Skip to content

Packed*Array CoW behavior doesnt mirror GDScript's #1968

Description

@coyo-t

Godot version

4.6

godot-cpp version

4.6

System information

win 10

Issue description

gdscript example that works as expected

class Something:
	func addToPacked (a:PackedVector2Array) -> void:
		a.append(Vector2.ONE)

	func addToTyped (a:Array[Vector2]) -> void:
		a.append(Vector2.ONE)

var it := Something.new()
var a := PackedVector2Array()
var b: Array[Vector2] = []

it.addToPacked(a)
it.addToTyped(b)

# a is [(1,1)]
# b is [(1,1)]

recreating in C++ (with other stuff omitted for brevity)

auto Something::addToPacked (PackedVector2Array array) -> void {
	array.append(Vector2(1,1));
}

auto Something::addToTyped (TypedArray<Vector2> array) -> void {
	array.append(Vector2(1,1));
}

auto Something::_bind_methods () -> void {
	ClassDB::bind_method(D_METHOD("addToPacked", "array"), &Something::addToPacked);
	ClassDB::bind_method(D_METHOD("addToTyped", "array"), &Something::addToTyped);
}

doing the above gdscript snippet with the gdextension version, a will be [] and b will be [(1,1)]
afaict the reason is that the packed array is having its Copy-on-Write triggered when it probably shouldnt be? (since both the above purely gdscript version as well as the docs say that packed arrays are passed by reference)
extremely obnoxious if intended (since the docs say that packed arrays are passed by reference, which they do in the GD version but not the C version)

Steps to reproduce

^

Minimal reproduction project

N/a

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions