diff options
author | Ignacio Etcheverry <ignalfonsore@gmail.com> | 2017-10-07 00:43:02 +0200 |
---|---|---|
committer | Ignacio Etcheverry <ignalfonsore@gmail.com> | 2017-10-07 00:43:02 +0200 |
commit | fdc3de009c41ba58a78a3579080a67ae6b699c84 (patch) | |
tree | cf7194256529a50d4692b8264f301c9fdd3b4ce6 /modules/mono/csharp_script.cpp | |
parent | 1d309439cbdaa21a75731bd8db28217690e829a2 (diff) | |
download | redot-engine-fdc3de009c41ba58a78a3579080a67ae6b699c84.tar.gz |
Mono: Make sure editor thread is attached on script reload
Diffstat (limited to 'modules/mono/csharp_script.cpp')
-rw-r--r-- | modules/mono/csharp_script.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp index 5301ea72b4..6f9e7f49df 100644 --- a/modules/mono/csharp_script.cpp +++ b/modules/mono/csharp_script.cpp @@ -1795,6 +1795,31 @@ RES ResourceFormatLoaderCSharpScript::load(const String &p_path, const String &p #endif script->set_path(p_original_path); + +#ifndef TOOLS_ENABLED + +#ifdef DEBUG_ENABLED + // User is responsible for thread attach/detach + ERR_EXPLAIN("Thread is not attached"); + CRASH_COND(mono_domain_get() == NULL); +#endif + +#else + if (Engine::get_singleton()->is_editor_hint() && mono_domain_get() == NULL) { + + CRASH_COND(Thread::get_caller_id() == Thread::get_main_id()); + + // Thread is not attached, but we will make an exception in this case + // because this may be called by one of the editor's worker threads. + // Attach this thread temporarily to reload the script. + + MonoThread *mono_thread = mono_thread_attach(SCRIPTS_DOMAIN); + CRASH_COND(mono_thread == NULL); + script->reload(); + mono_thread_detach(mono_thread); + + } else // just reload it normally +#endif script->reload(); if (r_error) |