Skip to content

[GDNative] Misleading godot_x_new_copy/operator_equal functions for array/dictionary/pool arrays #35542

Open
@touilleMan

Description

I order to copy an array (same thing for a dictionary and pool array) you should use godot_array_new_copy array... but if you want to copy the array you should use godot_array_duplicate ! :trollface:

The difference comes from the fact godot_array is a cheap structure pointing on a ref counted vector.
Using godot_array_new_copy only copy the cheap structure where godot_array_duplicate also copy the vector. In the first case we end up with a single array referenced by two godot_array variables, in the second we have two totally different arrays each referenced by their own godot_array variable.

This is even worst for pool arrays given they don't provide duplicate function, so user reading the api is really enclined to think godot_pool_x_array_new_copy is the way to do a duplication !

I personally got bitten by this multiple times, so I guess we should try to clarify a bit the naming here.

I guess renaming godot_x_new_copy into godot_x_new_reference would be enough, what do you think ?

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions