summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGeorge Marques <george@gmarqu.es>2020-01-09 13:59:33 -0300
committerGeorge Marques <george@gmarqu.es>2020-01-09 13:59:33 -0300
commit3718f8f5925bad0662d9ae84192d094b5da4d644 (patch)
tree2eae81ee33b67e204def8ea4b9e549c89e5753bf /core
parente97e951741c5f1a5865e1b551edb184af6374999 (diff)
downloadredot-engine-3718f8f5925bad0662d9ae84192d094b5da4d644.tar.gz
GDScript: Validate object instance on `is` operation
Avoids crashes on debug mode. Instead it now breaks the execution and show the error in-editor. Will still crash on release. Also add a similar check to Marshalls to ensure the debugger doesn't crash when trying to serialize the invalid instance.
Diffstat (limited to 'core')
-rw-r--r--core/io/marshalls.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp
index 8c8f65c3a0..e847a9cf0c 100644
--- a/core/io/marshalls.cpp
+++ b/core/io/marshalls.cpp
@@ -803,6 +803,18 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
}
} break;
case Variant::OBJECT: {
+#ifdef DEBUG_ENABLED
+ // Test for potential wrong values sent by the debugger when it breaks.
+ Object *obj = p_variant;
+ if (!obj || !ObjectDB::instance_validate(obj)) {
+ // Object is invalid, send a NULL instead.
+ if (buf) {
+ encode_uint32(Variant::NIL, buf);
+ }
+ r_len += 4;
+ return OK;
+ }
+#endif // DEBUG_ENABLED
if (!p_full_objects) {
flags |= ENCODE_FLAG_OBJECT_AS_ID;
}