Skip to content

Commit 047671d

Browse files
committedMar 1, 2023
Fix crash in resource load
1 parent 1bd0b29 commit 047671d

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed
 

‎core/io/resource_loader.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -483,13 +483,21 @@ Ref<Resource> ResourceLoader::load_threaded_get(const String &p_path, Error *r_e
483483
print_lt("GET: load count: " + itos(thread_loading_count) + " / wait count: " + itos(thread_waiting_count) + " / suspended count: " + itos(thread_suspended_count) + " / active: " + itos(thread_loading_count - thread_suspended_count));
484484
}
485485

486+
bool still_valid = true;
487+
bool was_thread = load_task.thread;
486488
do {
487489
load_task.cond_var->wait(thread_load_lock);
490+
if (!thread_load_tasks.has(local_path)) { //may have been erased during unlock and this was always an invalid call
491+
still_valid = false;
492+
break;
493+
}
488494
} while (load_task.cond_var); // In case of spurious wakeup.
489495

490-
thread_suspended_count--;
496+
if (was_thread) {
497+
thread_suspended_count--;
498+
}
491499

492-
if (!thread_load_tasks.has(local_path)) { //may have been erased during unlock and this was always an invalid call
500+
if (!still_valid) {
493501
if (r_error) {
494502
*r_error = ERR_INVALID_PARAMETER;
495503
}

0 commit comments

Comments
 (0)
Please sign in to comment.