[Core] Fix TypedArray encoding when full objects is disabled

This commit is contained in:
Fabio Alessandrelli 2024-07-13 10:32:44 +02:00
parent da4f6e439c
commit 31454423ba
1 changed files with 13 additions and 5 deletions

View File

@ -1315,10 +1315,12 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
if (array.is_typed()) { if (array.is_typed()) {
Ref<Script> script = array.get_typed_script(); Ref<Script> script = array.get_typed_script();
if (script.is_valid()) { if (script.is_valid()) {
header |= HEADER_DATA_FIELD_TYPED_ARRAY_SCRIPT; header |= p_full_objects ? HEADER_DATA_FIELD_TYPED_ARRAY_SCRIPT : HEADER_DATA_FIELD_TYPED_ARRAY_CLASS_NAME;
} else if (array.get_typed_class_name() != StringName()) { } else if (array.get_typed_class_name() != StringName()) {
header |= HEADER_DATA_FIELD_TYPED_ARRAY_CLASS_NAME; header |= HEADER_DATA_FIELD_TYPED_ARRAY_CLASS_NAME;
} else { } else {
// No need to check `p_full_objects` since for `Variant::OBJECT`
// `array.get_typed_class_name()` should be non-empty.
header |= HEADER_DATA_FIELD_TYPED_ARRAY_BUILTIN; header |= HEADER_DATA_FIELD_TYPED_ARRAY_BUILTIN;
} }
} }
@ -1783,12 +1785,18 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
Variant variant = array.get_typed_script(); Variant variant = array.get_typed_script();
Ref<Script> script = variant; Ref<Script> script = variant;
if (script.is_valid()) { if (script.is_valid()) {
if (p_full_objects) {
String path = script->get_path(); String path = script->get_path();
ERR_FAIL_COND_V_MSG(path.is_empty() || !path.begins_with("res://"), ERR_UNAVAILABLE, "Failed to encode a path to a custom script for an array type."); ERR_FAIL_COND_V_MSG(path.is_empty() || !path.begins_with("res://"), ERR_UNAVAILABLE, "Failed to encode a path to a custom script for an array type.");
_encode_string(path, buf, r_len); _encode_string(path, buf, r_len);
} else if (array.get_typed_class_name() != StringName()) {
_encode_string(array.get_typed_class_name(), buf, r_len);
} else { } else {
_encode_string(EncodedObjectAsID::get_class_static(), buf, r_len);
}
} else if (array.get_typed_class_name() != StringName()) {
_encode_string(p_full_objects ? array.get_typed_class_name().operator String() : EncodedObjectAsID::get_class_static(), buf, r_len);
} else {
// No need to check `p_full_objects` since for `Variant::OBJECT`
// `array.get_typed_class_name()` should be non-empty.
if (buf) { if (buf) {
encode_uint32(array.get_typed_builtin(), buf); encode_uint32(array.get_typed_builtin(), buf);
buf += 4; buf += 4;