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.cpp68
1 files changed, 42 insertions, 26 deletions
diff --git a/modules/gdscript/gdscript_function.cpp b/modules/gdscript/gdscript_function.cpp
index 452b1933eb..cbf7d81a61 100644
--- a/modules/gdscript/gdscript_function.cpp
+++ b/modules/gdscript/gdscript_function.cpp
@@ -137,18 +137,19 @@ static String _get_var_type(const Variant *p_var) {
String basestr;
if (p_var->get_type() == Variant::OBJECT) {
- Object *bobj = *p_var;
+ bool was_freed;
+ Object *bobj = p_var->get_validated_object_with_check(was_freed);
if (!bobj) {
- basestr = "null instance";
- } else {
- if (ObjectDB::instance_validate(bobj)) {
- if (bobj->get_script_instance())
- basestr = bobj->get_class() + " (" + bobj->get_script_instance()->get_script()->get_path().get_file() + ")";
- else
- basestr = bobj->get_class();
+ if (was_freed) {
+ basestr = "null instance";
} else {
- basestr = "previously freed instance";
+ basestr = "previously freed";
}
+ } else {
+ if (bobj->get_script_instance())
+ basestr = bobj->get_class() + " (" + bobj->get_script_instance()->get_script()->get_path().get_file() + ")";
+ else
+ basestr = bobj->get_class();
}
} else {
@@ -497,14 +498,26 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
bool extends_ok = false;
if (a->get_type() == Variant::OBJECT && a->operator Object *() != NULL) {
- 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.";
+ bool was_freed;
+ Object *obj_A = a->get_validated_object_with_check(was_freed);
+
+ if (was_freed) {
+ err_text = "Left operand of 'is' is a previously freed instance.";
OPCODE_BREAK;
}
+
+ Object *obj_B = b->get_validated_object_with_check(was_freed);
+
+ if (was_freed) {
+ err_text = "Right operand of 'is' is a previously freed instance.";
+ OPCODE_BREAK;
+ }
+#else
+
+ Object *obj_A = *a;
+ Object *obj_B = *b;
#endif // DEBUG_ENABLED
GDScript *scr_B = Object::cast_to<GDScript>(obj_B);
@@ -1274,7 +1287,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
gdfs->state.script = Ref<GDScript>(_script);
gdfs->state.ip = ip + ipofs;
gdfs->state.line = line;
- gdfs->state.instance_id = (p_instance && p_instance->get_owner()) ? p_instance->get_owner()->get_instance_id() : 0;
+ gdfs->state.instance_id = (p_instance && p_instance->get_owner()) ? p_instance->get_owner()->get_instance_id() : ObjectID();
//gdfs->state.result_pos=ip+ipofs-1;
gdfs->state.defarg = defarg;
gdfs->state.instance = p_instance;
@@ -1298,20 +1311,20 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
}
#endif
- Object *obj = argobj->operator Object *();
+#ifdef DEBUG_ENABLED
+ bool was_freed;
+ Object *obj = argobj->get_validated_object_with_check(was_freed);
String signal = argname->operator String();
-#ifdef DEBUG_ENABLED
+ if (was_freed) {
+ err_text = "First argument of yield() is a previously freed instance.";
+ OPCODE_BREAK;
+ }
+
if (!obj) {
err_text = "First argument of yield() is null.";
OPCODE_BREAK;
}
- if (ScriptDebugger::get_singleton()) {
- if (!ObjectDB::instance_validate(obj)) {
- err_text = "First argument of yield() is a previously freed instance.";
- OPCODE_BREAK;
- }
- }
if (signal.length() == 0) {
err_text = "Second argument of yield() is an empty string (for signal name).";
@@ -1324,6 +1337,9 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE_BREAK;
}
#else
+ Object *obj = argobj->operator Object *();
+ String signal = argname->operator String();
+
obj->connect(signal, gdfs.ptr(), "_signal_callback", varray(gdfs), Object::CONNECT_ONESHOT);
#endif
}
@@ -1565,14 +1581,14 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
//error
// function, file, line, error, explanation
String err_file;
- if (p_instance && ObjectDB::instance_validate(p_instance->owner) && p_instance->script->is_valid() && p_instance->script->path != "")
+ if (p_instance && ObjectDB::get_instance(p_instance->owner_id) != nullptr && p_instance->script->is_valid() && p_instance->script->path != "")
err_file = p_instance->script->path;
else if (script)
err_file = script->path;
if (err_file == "")
err_file = "<built-in>";
String err_func = name;
- if (p_instance && ObjectDB::instance_validate(p_instance->owner) && p_instance->script->is_valid() && p_instance->script->name != "")
+ if (p_instance && ObjectDB::get_instance(p_instance->owner_id) != nullptr && p_instance->script->is_valid() && p_instance->script->name != "")
err_func = p_instance->script->name + "." + err_func;
int err_line = line;
if (err_text == "") {
@@ -1829,7 +1845,7 @@ bool GDScriptFunctionState::is_valid(bool p_extended_check) const {
if (p_extended_check) {
//class instance gone?
- if (state.instance_id && !ObjectDB::get_instance(state.instance_id))
+ if (state.instance_id.is_valid() && !ObjectDB::get_instance(state.instance_id))
return false;
}
@@ -1839,7 +1855,7 @@ bool GDScriptFunctionState::is_valid(bool p_extended_check) const {
Variant GDScriptFunctionState::resume(const Variant &p_arg) {
ERR_FAIL_COND_V(!function, Variant());
- if (state.instance_id && !ObjectDB::get_instance(state.instance_id)) {
+ if (state.instance_id.is_valid() && !ObjectDB::get_instance(state.instance_id)) {
#ifdef DEBUG_ENABLED
ERR_FAIL_V_MSG(Variant(), "Resumed function '" + String(function->get_name()) + "()' after yield, but class instance is gone. At script: " + state.script->get_path() + ":" + itos(state.line));
#else