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
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)
the GD version used packed arrays but yeah that didnt work when ported. Cool. Great. -.-
guess this is why the packed arrays dont have bulk copy from->into methods ¬_¬
Yes, this helps if you then use VariantInternal to grab the pointer to the packed array inside.
However, the consistency is limited since it only works if you're getting call'd (e.g. from GDScript). If someone uses ptrcall, the semantics flip, and this workaround won't work.
had some previous experience connect in my head that might be a fine soultion to this
so in old versions of GML, arrays passed to functions/scripts had this same CoW behavior (tmk it wasnt for multithreading though it was one of the many things inherited by its original parent Delphi), but there was a way to manually override the behavior. i dont think it had a name but it could be called the "array accessor" or "at array", idk
function something (_input) {
var a = _input[0] // doesnt trigger cow, Duh.
_input[@ 1] = 10// doesnt trigger, uses the [@ accessor
_input[2] = 20// triggers, now operating on a copy of the array rather than itself
}
i dont know what to call this for GD++ but im thinking something like this?
autosomething (PackedByteArray input) -> void {
auto a = input[0]; // no COWauto middlethem = input.cow_tools_jpg(); // terrible name, idk what to call it though
middlethem.append_array({ 2, 9, 2 }); // no COW triggered
input.append({ 2, 0, 2 }); // COW triggered, input is now a copy of the data (though it has middle's changes)
}
if i find it in me ill try to make my own version of this as a PR or something
i think the hardest part of this will be thinking of a name for it get_cowless_proxy? nehh get_explicitly_writable? get_thread_unsafe_writable? get_version_that_lets_me_write_to_you_without_triggering_copy_on_write_you_gormless_construct?
:P i dont think the COW behavior should be toggleable by the user on the object itself though. i feel like that causes more problems than it solves. i also dont think a PackedByteArray and a PBA_Cowless should be interchangable (but they can be convertable to and from using the get_* methods)
Activity
Ivorforce commentedon Apr 10, 2026
Hello, this is a documented discrepancy, see https://docs.godotengine.org/en/stable/tutorials/scripting/cpp/core_types.html#packed-arrays
coyo-t commentedon Apr 10, 2026
yeah okay thats peak obnoxiousness .-. thanks anyway
for reference im using "out" arrays for building geometry data; current version is:
the GD version used packed arrays but yeah that didnt work when ported. Cool. Great. -.-
guess this is why the packed arrays dont have bulk copy from->into methods ¬_¬
dsnopek commentedon Apr 10, 2026
@Ivorforce I vaguely recall there being a workaround for this, I think by using
Variantas the argument rather than the packed array type?Ivorforce commentedon Apr 10, 2026
Yes, this helps if you then use
VariantInternalto grab the pointer to the packed array inside.However, the consistency is limited since it only works if you're getting
call'd (e.g. from GDScript). If someone usesptrcall, the semantics flip, and this workaround won't work.coyo-t commentedon Apr 13, 2026
had some previous experience connect in my head that might be a fine soultion to this
so in old versions of GML, arrays passed to functions/scripts had this same CoW behavior (tmk it wasnt for multithreading though it was one of the many things inherited by its original parent Delphi), but there was a way to manually override the behavior. i dont think it had a name but it could be called the "array accessor" or "at array", idk
i dont know what to call this for GD++ but im thinking something like this?
if i find it in me ill try to make my own version of this as a PR or something
i think the hardest part of this will be thinking of a name for it
get_cowless_proxy? nehhget_explicitly_writable?get_thread_unsafe_writable?get_version_that_lets_me_write_to_you_without_triggering_copy_on_write_you_gormless_construct?:P i dont think the COW behavior should be toggleable by the user on the object itself though. i feel like that causes more problems than it solves. i also dont think a
PackedByteArrayand aPBA_Cowlessshould be interchangable (but they can be convertable to and from using theget_*methods)