summaryrefslogtreecommitdiff
path: root/modules/gdscript/gdscript_function.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gdscript/gdscript_function.cpp')
-rw-r--r--modules/gdscript/gdscript_function.cpp35
1 files changed, 20 insertions, 15 deletions
diff --git a/modules/gdscript/gdscript_function.cpp b/modules/gdscript/gdscript_function.cpp
index 0a01321851..452b1933eb 100644
--- a/modules/gdscript/gdscript_function.cpp
+++ b/modules/gdscript/gdscript_function.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -67,23 +67,23 @@ Variant *GDScriptFunction::_get_variant(int p_address, GDScriptInstance *p_insta
case ADDR_TYPE_CLASS_CONSTANT: {
//todo change to index!
- GDScript *o = p_script;
+ GDScript *s = p_script;
#ifdef DEBUG_ENABLED
ERR_FAIL_INDEX_V(address, _global_names_count, NULL);
#endif
const StringName *sn = &_global_names_ptr[address];
- while (o) {
- GDScript *s = o;
- while (s) {
+ while (s) {
+ GDScript *o = s;
+ while (o) {
- Map<StringName, Variant>::Element *E = s->constants.find(*sn);
+ Map<StringName, Variant>::Element *E = o->constants.find(*sn);
if (E) {
return &E->get();
}
- s = s->_base;
+ o = o->_owner;
}
- o = o->_owner;
+ s = s->_base;
}
ERR_FAIL_V_MSG(NULL, "GDScriptCompiler bug.");
@@ -500,6 +500,13 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
Object *obj_A = *a;
Object *obj_B = *b;
+#ifdef DEBUG_ENABLED
+ if (!ObjectDB::instance_validate(obj_A)) {
+ err_text = "Left operand of 'is' was already freed.";
+ OPCODE_BREAK;
+ }
+#endif // DEBUG_ENABLED
+
GDScript *scr_B = Object::cast_to<GDScript>(obj_B);
if (scr_B) {
@@ -764,15 +771,17 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
GET_VARIANT_PTR(dst, 2);
GET_VARIANT_PTR(src, 3);
-#ifdef DEBUG_ENABLED
Variant::Type var_type = (Variant::Type)_code_ptr[ip + 1];
GD_ERR_BREAK(var_type < 0 || var_type >= Variant::VARIANT_MAX);
if (src->get_type() != var_type) {
+#ifdef DEBUG_ENABLED
if (Variant::can_convert_strict(src->get_type(), var_type)) {
+#endif // DEBUG_ENABLED
Variant::CallError ce;
*dst = Variant::construct(var_type, const_cast<const Variant **>(&src), 1, ce);
} else {
+#ifdef DEBUG_ENABLED
err_text = "Trying to assign value of type '" + Variant::get_type_name(src->get_type()) +
"' to a variable of type '" + Variant::get_type_name(var_type) + "'.";
OPCODE_BREAK;
@@ -780,9 +789,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
} else {
#endif // DEBUG_ENABLED
*dst = *src;
-#ifdef DEBUG_ENABLED
}
-#endif // DEBUG_ENABLED
ip += 4;
}
@@ -1543,10 +1550,8 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE_BREAK;
}
-// Enable for debugging
-#if 0
+#if 0 // Enable for debugging.
default: {
-
err_text = "Illegal opcode " + itos(_code_ptr[ip]) + " at address " + itos(ip);
OPCODE_BREAK;
}