Merge pull request #32534 from Xrayez/fix-dict2inst-init

Make `dict2inst` to work with arbitrary `_init` parameters
This commit is contained in:
Rémi Verschelde 2020-05-03 09:58:07 +02:00 committed by GitHub
commit 3c200b23fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 9 deletions

View File

@ -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;
}

View File

@ -1197,8 +1197,7 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_
return;
}
}
r_ret = gdscr->_new(nullptr, 0, r_error);
r_ret = gdscr->_new(nullptr, -1 /*skip initializer*/, r_error);
GDScriptInstance *ins = static_cast<GDScriptInstance *>(static_cast<Object *>(r_ret)->get_script_instance());
Ref<GDScript> gd_ref = ins->get_script();