2
0
Fork 0

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.
3.x
Andrii Doroshenko (Xrayez) 2019-10-04 00:01:12 +07:00 committed by Hugo Locurcio
parent 0f10eafb38
commit accdd575f6
No known key found for this signature in database
GPG Key ID: 39E8F8BE30B0A49C
2 changed files with 5 additions and 4 deletions

@ -110,6 +110,9 @@ GDScriptInstance *GDScript::_create_instance(const Variant **p_args, int p_argco
instances.insert(instance->owner);
GDScriptLanguage::singleton->lock.unlock();
if (p_argcount < 0) {
return instance;
}
initializer->call(instance, p_args, p_argcount, r_error);
if (r_error.error != Variant::CallError::CALL_OK) {
@ -123,9 +126,8 @@ GDScriptInstance *GDScript::_create_instance(const Variant **p_args, int p_argco
GDScriptLanguage::singleton->lock.unlock();
#endif
ERR_FAIL_COND_V(r_error.error != Variant::CallError::CALL_OK, nullptr); //error constructing
ERR_FAIL_V_MSG(nullptr, "Error constructing a GDScriptInstance.");
}
//@TODO make thread safe
return instance;
}

@ -1153,8 +1153,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);
if (r_error.error != Variant::CallError::CALL_OK) {
r_ret = Variant();