Fix deadlock in cyclic resource load

This commit is contained in:
Pedro J. Estébanez 2023-02-26 17:17:41 +01:00
parent 1bd0b296e1
commit b60197d1c6

View File

@ -447,8 +447,16 @@ Ref<Resource> ResourceLoader::load_threaded_get(const String &p_path, Error *r_e
ThreadLoadTask &load_task = thread_load_tasks[local_path];
if (!load_task.cond_var && load_task.status == THREAD_LOAD_IN_PROGRESS) {
// A condition variable was never created for this task.
if (load_task.status == THREAD_LOAD_IN_PROGRESS) {
if (load_task.loader_id == Thread::get_caller_id()) {
// Load is in progress, but it's precisely this thread the one in charge.
// That means this is a cyclic load.
if (r_error) {
*r_error = ERR_BUSY;
}
return Ref<Resource>();
} else if (!load_task.cond_var) {
// Load is in progress, but a condition variable was never created for it.
// That happens when a load has been initiated with subthreads disabled,
// but now another load thread needs to interact with this one (either
// because of subthreads being used this time, or because it's simply a
@ -457,6 +465,7 @@ Ref<Resource> ResourceLoader::load_threaded_get(const String &p_path, Error *r_e
// condition variable now.
load_task.cond_var = memnew(ConditionVariable);
}
}
//cond var still exists, meaning it's still loading, request poll
if (load_task.cond_var) {