Skip to content

Commit 5640e8a

Browse files
committed
ResourceLoader: Let resource setup late steps invoke loading in turn
1 parent 88d9325 commit 5640e8a

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

core/io/resource_loader.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,14 @@ void ResourceLoader::_thread_load_function(void *p_userdata) {
345345

346346
bool ignoring = load_task.cache_mode == ResourceFormatLoader::CACHE_MODE_IGNORE || load_task.cache_mode == ResourceFormatLoader::CACHE_MODE_IGNORE_DEEP;
347347
bool replacing = load_task.cache_mode == ResourceFormatLoader::CACHE_MODE_REPLACE || load_task.cache_mode == ResourceFormatLoader::CACHE_MODE_REPLACE_DEEP;
348+
bool unlock_pending = true;
348349
if (load_task.resource.is_valid()) {
350+
// From now on, no critical section needed as no one will write to the task anymore.
351+
// Moreover, the mutex being unlocked is a requirement if some of the calls below
352+
// that set the resource up invoke code that in turn requests resource loading.
353+
thread_load_mutex.unlock();
354+
unlock_pending = false;
355+
349356
if (!ignoring) {
350357
if (replacing) {
351358
Ref<Resource> old_res = ResourceCache::get_ref(load_task.local_path);
@@ -383,13 +390,18 @@ void ResourceLoader::_thread_load_function(void *p_userdata) {
383390
load_task.status = THREAD_LOAD_LOADED;
384391
load_task.progress = 1.0;
385392

393+
thread_load_mutex.unlock();
394+
unlock_pending = false;
395+
386396
if (_loaded_callback) {
387397
_loaded_callback(load_task.resource, load_task.local_path);
388398
}
389399
}
390400
}
391401

392-
thread_load_mutex.unlock();
402+
if (unlock_pending) {
403+
thread_load_mutex.unlock();
404+
}
393405

394406
if (load_nesting == 0) {
395407
if (own_mq_override) {

0 commit comments

Comments
 (0)