summaryrefslogtreecommitdiffstats
path: root/core/io/resource_loader.cpp
diff options
context:
space:
mode:
authorPedro J. Estébanez <pedrojrulez@gmail.com>2024-07-29 13:40:29 +0200
committerPedro J. Estébanez <pedrojrulez@gmail.com>2024-07-29 18:13:37 +0200
commit5640e8adc9f80c237c8e373b68c3e2ced610578d (patch)
treefc72901275e5173e449e74d9a159afa1c3109725 /core/io/resource_loader.cpp
parent88d9325065a3e00e9e168ffad4ff93e12455a357 (diff)
downloadredot-engine-5640e8adc9f80c237c8e373b68c3e2ced610578d.tar.gz
ResourceLoader: Let resource setup late steps invoke loading in turn
Diffstat (limited to 'core/io/resource_loader.cpp')
-rw-r--r--core/io/resource_loader.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp
index d606db620c..2b5e83264e 100644
--- a/core/io/resource_loader.cpp
+++ b/core/io/resource_loader.cpp
@@ -345,7 +345,14 @@ void ResourceLoader::_thread_load_function(void *p_userdata) {
bool ignoring = load_task.cache_mode == ResourceFormatLoader::CACHE_MODE_IGNORE || load_task.cache_mode == ResourceFormatLoader::CACHE_MODE_IGNORE_DEEP;
bool replacing = load_task.cache_mode == ResourceFormatLoader::CACHE_MODE_REPLACE || load_task.cache_mode == ResourceFormatLoader::CACHE_MODE_REPLACE_DEEP;
+ bool unlock_pending = true;
if (load_task.resource.is_valid()) {
+ // From now on, no critical section needed as no one will write to the task anymore.
+ // Moreover, the mutex being unlocked is a requirement if some of the calls below
+ // that set the resource up invoke code that in turn requests resource loading.
+ thread_load_mutex.unlock();
+ unlock_pending = false;
+
if (!ignoring) {
if (replacing) {
Ref<Resource> old_res = ResourceCache::get_ref(load_task.local_path);
@@ -383,13 +390,18 @@ void ResourceLoader::_thread_load_function(void *p_userdata) {
load_task.status = THREAD_LOAD_LOADED;
load_task.progress = 1.0;
+ thread_load_mutex.unlock();
+ unlock_pending = false;
+
if (_loaded_callback) {
_loaded_callback(load_task.resource, load_task.local_path);
}
}
}
- thread_load_mutex.unlock();
+ if (unlock_pending) {
+ thread_load_mutex.unlock();
+ }
if (load_nesting == 0) {
if (own_mq_override) {