Skip to content

Commit 56dfed4

Browse files
committed
Merge pull request godotengine#90751 from dalexeev/core-marshalls-fix-objects-as-id-in-typed-arrays
Core: Fix binary serialization of objects in typed arrays
2 parents ce13f0c + 27b94eb commit 56dfed4

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

core/io/marshalls.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -794,34 +794,40 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
794794

795795
ERR_FAIL_INDEX_V(bt, Variant::VARIANT_MAX, ERR_INVALID_DATA);
796796
builtin_type = (Variant::Type)bt;
797-
ERR_FAIL_COND_V(!p_allow_objects && builtin_type == Variant::OBJECT, ERR_UNAUTHORIZED);
797+
if (!p_allow_objects && builtin_type == Variant::OBJECT) {
798+
class_name = EncodedObjectAsID::get_class_static();
799+
}
798800
} break;
799801
case HEADER_DATA_FIELD_TYPED_ARRAY_CLASS_NAME: {
800-
ERR_FAIL_COND_V(!p_allow_objects, ERR_UNAUTHORIZED);
801-
802802
String str;
803803
Error err = _decode_string(buf, len, r_len, str);
804804
if (err) {
805805
return err;
806806
}
807807

808808
builtin_type = Variant::OBJECT;
809-
class_name = str;
809+
if (p_allow_objects) {
810+
class_name = str;
811+
} else {
812+
class_name = EncodedObjectAsID::get_class_static();
813+
}
810814
} break;
811815
case HEADER_DATA_FIELD_TYPED_ARRAY_SCRIPT: {
812-
ERR_FAIL_COND_V(!p_allow_objects, ERR_UNAUTHORIZED);
813-
814816
String path;
815817
Error err = _decode_string(buf, len, r_len, path);
816818
if (err) {
817819
return err;
818820
}
819-
ERR_FAIL_COND_V_MSG(path.is_empty() || !path.begins_with("res://") || !ResourceLoader::exists(path, "Script"), ERR_INVALID_DATA, "Invalid script path: '" + path + "'.");
820-
script = ResourceLoader::load(path, "Script");
821-
ERR_FAIL_COND_V_MSG(script.is_null(), ERR_INVALID_DATA, "Can't load script at path: '" + path + "'.");
822821

823822
builtin_type = Variant::OBJECT;
824-
class_name = script->get_instance_base_type();
823+
if (p_allow_objects) {
824+
ERR_FAIL_COND_V_MSG(path.is_empty() || !path.begins_with("res://") || !ResourceLoader::exists(path, "Script"), ERR_INVALID_DATA, "Invalid script path: '" + path + "'.");
825+
script = ResourceLoader::load(path, "Script");
826+
ERR_FAIL_COND_V_MSG(script.is_null(), ERR_INVALID_DATA, "Can't load script at path: '" + path + "'.");
827+
class_name = script->get_instance_base_type();
828+
} else {
829+
class_name = EncodedObjectAsID::get_class_static();
830+
}
825831
} break;
826832
default:
827833
ERR_FAIL_V(ERR_INVALID_DATA); // Future proofing.
@@ -1243,13 +1249,10 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
12431249
if (array.is_typed()) {
12441250
Ref<Script> script = array.get_typed_script();
12451251
if (script.is_valid()) {
1246-
ERR_FAIL_COND_V(!p_full_objects, ERR_UNAVAILABLE);
12471252
header |= HEADER_DATA_FIELD_TYPED_ARRAY_SCRIPT;
12481253
} else if (array.get_typed_class_name() != StringName()) {
1249-
ERR_FAIL_COND_V(!p_full_objects, ERR_UNAVAILABLE);
12501254
header |= HEADER_DATA_FIELD_TYPED_ARRAY_CLASS_NAME;
12511255
} else {
1252-
ERR_FAIL_COND_V(!p_full_objects && array.get_typed_builtin() == Variant::OBJECT, ERR_UNAVAILABLE);
12531256
header |= HEADER_DATA_FIELD_TYPED_ARRAY_BUILTIN;
12541257
}
12551258
}

0 commit comments

Comments
 (0)