summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorIgnacio Etcheverry <ignalfonsore@gmail.com>2019-02-04 20:39:02 +0100
committerIgnacio Etcheverry <ignalfonsore@gmail.com>2019-02-09 00:32:18 +0100
commit9df44c2d2cbae10aa7b27b2562d00d69c2caecb8 (patch)
treea27782b053e2603dedf350fdd7fd49e39b76c530 /core
parent16d402147b9057c9f7d43ef9b46eb8654e5483cc (diff)
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.
Diffstat (limited to 'core')
-rw-r--r--core/object.cpp15
-rw-r--r--core/object.h1
-rw-r--r--core/script_language.cpp2
-rw-r--r--core/script_language.h3
4 files changed, 18 insertions, 3 deletions
diff --git a/core/object.cpp b/core/object.cpp
index 05e661baab..b30ae1f512 100644
--- a/core/object.cpp
+++ b/core/object.cpp
@@ -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]);
+ }
}
}
}
diff --git a/core/object.h b/core/object.h
index 5bfef8a439..9a5217e3de 100644
--- a/core/object.h
+++ b/core/object.h
@@ -730,6 +730,7 @@ public:
//used by script languages to store binding data
void *get_script_instance_binding(int p_script_language_index);
bool has_script_instance_binding(int p_script_language_index);
+ void set_script_instance_binding(int p_script_language_index, void *p_data);
void clear_internal_resource_paths();
diff --git a/core/script_language.cpp b/core/script_language.cpp
index 632fa3b336..2746c015d6 100644
--- a/core/script_language.cpp
+++ b/core/script_language.cpp
@@ -37,6 +37,7 @@ int ScriptServer::_language_count = 0;
bool ScriptServer::scripting_enabled = true;
bool ScriptServer::reload_scripts_on_save = false;
+bool ScriptServer::languages_finished = false;
ScriptEditRequestFunction ScriptServer::edit_request_func = NULL;
void Script::_notification(int p_what) {
@@ -130,6 +131,7 @@ void ScriptServer::finish_languages() {
_languages[i]->finish();
}
global_classes_clear();
+ languages_finished = true;
}
void ScriptServer::set_reload_scripts_on_save(bool p_enable) {
diff --git a/core/script_language.h b/core/script_language.h
index b0f12dc291..2d35097692 100644
--- a/core/script_language.h
+++ b/core/script_language.h
@@ -54,6 +54,7 @@ class ScriptServer {
static int _language_count;
static bool scripting_enabled;
static bool reload_scripts_on_save;
+ static bool languages_finished;
struct GlobalScriptClass {
StringName language;
@@ -91,6 +92,8 @@ public:
static void init_languages();
static void finish_languages();
+
+ static bool are_languages_finished() { return languages_finished; }
};
class ScriptInstance;