Use script instance binding for objects constructed from C#

Only possible if the object class is a "native type". If the object class is a user class (that derives a "native type") then a script is needed.
Since CSharpLanguage does cleanup of script instance bindings when finished, cases like #25621 will no longer cause problems.

Fixed ~Object() trying to free script instance bindings after the language has already been removed, which would result in a NULL dereference.
This commit is contained in:
Ignacio Etcheverry 2019-02-04 20:39:02 +01:00
parent 16d402147b
commit 9df44c2d2c
9 changed files with 88 additions and 19 deletions

View file

@ -1929,6 +1929,13 @@ bool Object::has_script_instance_binding(int p_script_language_index) {
return _script_instance_bindings[p_script_language_index] != NULL;
}
void Object::set_script_instance_binding(int p_script_language_index, void *p_data) {
#ifdef DEBUG_ENABLED
CRASH_COND(_script_instance_bindings[p_script_language_index] != NULL);
#endif
_script_instance_bindings[p_script_language_index] = p_data;
}
Object::Object() {
_class_ptr = NULL;
@ -1992,9 +1999,11 @@ Object::~Object() {
_instance_ID = 0;
_predelete_ok = 2;
for (int i = 0; i < MAX_SCRIPT_INSTANCE_BINDINGS; i++) {
if (_script_instance_bindings[i]) {
ScriptServer::get_language(i)->free_instance_binding_data(_script_instance_bindings[i]);
if (!ScriptServer::are_languages_finished()) {
for (int i = 0; i < MAX_SCRIPT_INSTANCE_BINDINGS; i++) {
if (_script_instance_bindings[i]) {
ScriptServer::get_language(i)->free_instance_binding_data(_script_instance_bindings[i]);
}
}
}
}