diff options
author | Pedro J. Estébanez <pedrojrulez@gmail.com> | 2023-05-10 10:00:33 +0200 |
---|---|---|
committer | Pedro J. Estébanez <pedrojrulez@gmail.com> | 2023-05-10 18:53:41 +0200 |
commit | 5a4613f5512b84a758d7cb4850f6e35db2bcceba (patch) | |
tree | 62b5c940e6793466941951fcf1eaafbbb3ab56aa /core/io | |
parent | 8983b20ccd2f8a91d87789f2c0dd90f4e31b8b2c (diff) | |
download | redot-engine-5a4613f5512b84a758d7cb4850f6e35db2bcceba.tar.gz |
Avoid sync issues in resources with deferred updates
Diffstat (limited to 'core/io')
-rw-r--r-- | core/io/resource_loader.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index a00593c679..932493e340 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -285,10 +285,15 @@ Ref<Resource> ResourceLoader::_load(const String &p_path, const String &p_origin void ResourceLoader::_thread_load_function(void *p_userdata) { ThreadLoadTask &load_task = *(ThreadLoadTask *)p_userdata; // Thread-safe either if it's the current thread or a brand new one. + CallQueue *mq_override = nullptr; if (load_task.first_in_stack) { if (!load_task.dependent_path.is_empty()) { load_paths_stack.push_back(load_task.dependent_path); } + if (!Thread::is_main_thread()) { + mq_override = memnew(CallQueue); + MessageQueue::set_thread_singleton_override(mq_override); + } } else { DEV_ASSERT(load_task.dependent_path.is_empty()); } @@ -346,6 +351,11 @@ void ResourceLoader::_thread_load_function(void *p_userdata) { print_lt("END: load count: " + itos(thread_active_count + thread_suspended_count) + " / wait count: " + itos(thread_waiting_count) + " / suspended count: " + itos(thread_suspended_count) + " / active: " + itos(thread_active_count)); thread_load_mutex.unlock(); + + if (load_task.first_in_stack && mq_override) { + memdelete(mq_override); + MessageQueue::set_thread_singleton_override(nullptr); + } } static String _validate_local_path(const String &p_path) { |