diff options
author | Andrii Doroshenko (Xrayez) <xrayez@gmail.com> | 2019-10-04 00:01:12 +0300 |
---|---|---|
committer | Andrii Doroshenko (Xrayez) <xrayez@gmail.com> | 2020-04-30 18:30:04 +0300 |
commit | 7001d06f9d7e11e042147899acbdd01c13ad8983 (patch) | |
tree | 21854fa8d131dd66064afc35d6eef0038963ecd0 /modules/gdscript/gdscript.cpp | |
parent | f870118323f9f1e4cd7d3ea63e951a2214f63c48 (diff) | |
download | redot-engine-7001d06f9d7e11e042147899acbdd01c13ad8983.tar.gz |
Make `dict2inst` to work with arbitrary `_init` parameters
This is achieved by skipping initializer call while creating an instance
of a GDScript. This is implemented by passing -1 as an argument count
to `_new` and interpreting any value below 0 to mean that the initializer
should not be called during instantiation, because internal members of
an instance are going to be overridden afterwards.
Diffstat (limited to 'modules/gdscript/gdscript.cpp')
-rw-r--r-- | modules/gdscript/gdscript.cpp | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index 98366f7957..719800d8af 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -103,15 +103,14 @@ GDScriptInstance *GDScript::_create_instance(const Variant **p_args, int p_argco instance->owner->set_script_instance(instance); /* STEP 2, INITIALIZE AND CONSTRUCT */ - { MutexLock lock(GDScriptLanguage::singleton->lock); - instances.insert(instance->owner); } - + if (p_argcount < 0) { + return instance; + } initializer->call(instance, p_args, p_argcount, r_error); - if (r_error.error != Callable::CallError::CALL_OK) { instance->script = Ref<GDScript>(); instance->owner->set_script_instance(nullptr); @@ -119,10 +118,8 @@ GDScriptInstance *GDScript::_create_instance(const Variant **p_args, int p_argco MutexLock lock(GDScriptLanguage::singleton->lock); instances.erase(p_owner); } - - ERR_FAIL_COND_V(r_error.error != Callable::CallError::CALL_OK, nullptr); //error constructing + ERR_FAIL_V_MSG(nullptr, "Error constructing a GDScriptInstance."); } - //@TODO make thread safe return instance; } |