diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index 04fd641f244..6d7db7a4a5c 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -772,6 +772,10 @@ Ref ResourceLoader::_load_complete(LoadToken &p_load_token, Error *r_e return _load_complete_inner(p_load_token, r_error, thread_load_lock); } +void ResourceLoader::set_is_import_thread(bool p_import_thread) { + import_thread = p_import_thread; +} + Ref ResourceLoader::_load_complete_inner(LoadToken &p_load_token, Error *r_error, MutexLock> &p_thread_load_lock) { if (r_error) { *r_error = OK; @@ -886,9 +890,11 @@ Ref ResourceLoader::_load_complete_inner(LoadToken &p_load_token, Erro MessageQueue::get_main_singleton()->push_callable(callable_mp(rcc.source, &Resource::connect_changed).bind(rcc.callable, rcc.flags)); } } - core_bind::Semaphore done; - MessageQueue::get_main_singleton()->push_callable(callable_mp(&done, &core_bind::Semaphore::post).bind(1)); - done.wait(); + if (!import_thread) { // Main thread is blocked by initial resource reimport, do not wait. + core_bind::Semaphore done; + MessageQueue::get_main_singleton()->push_callable(callable_mp(&done, &core_bind::Semaphore::post).bind(1)); + done.wait(); + } } } } @@ -1565,6 +1571,7 @@ bool ResourceLoader::create_missing_resources_if_class_unavailable = false; bool ResourceLoader::abort_on_missing_resource = true; bool ResourceLoader::timestamp_on_load = false; +thread_local bool ResourceLoader::import_thread = false; thread_local int ResourceLoader::load_nesting = 0; thread_local Vector ResourceLoader::load_paths_stack; thread_local HashMap>> ResourceLoader::res_ref_overrides; diff --git a/core/io/resource_loader.h b/core/io/resource_loader.h index 20bffc076c5..18f1f42817c 100644 --- a/core/io/resource_loader.h +++ b/core/io/resource_loader.h @@ -204,6 +204,7 @@ private: static void _run_load_task(void *p_userdata); + static thread_local bool import_thread; static thread_local int load_nesting; static thread_local HashMap>> res_ref_overrides; // Outermost key is nesting level. static thread_local Vector load_paths_stack; @@ -253,6 +254,8 @@ public: static bool is_imported(const String &p_path); static int get_import_order(const String &p_path); + static void set_is_import_thread(bool p_import_thread); + static void set_timestamp_on_load(bool p_timestamp) { timestamp_on_load = p_timestamp; } static bool get_timestamp_on_load() { return timestamp_on_load; } diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp index 16a7578d8ac..997bab9a12d 100644 --- a/editor/editor_file_system.cpp +++ b/editor/editor_file_system.cpp @@ -3107,8 +3107,11 @@ void EditorFileSystem::_refresh_filesystem() { } void EditorFileSystem::_reimport_thread(uint32_t p_index, ImportThreadData *p_import_data) { + ResourceLoader::set_is_import_thread(true); int file_idx = p_import_data->reimport_from + int(p_index); _reimport_file(p_import_data->reimport_files[file_idx].path); + ResourceLoader::set_is_import_thread(false); + p_import_data->imported_sem->post(); }