summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPedro J. Estébanez <pedrojrulez@gmail.com>2023-03-01 11:11:40 +0100
committerYuri Sizov <yuris@humnom.net>2023-03-27 16:57:35 +0200
commit46d475b067dcab6929fa76d1aad9bc6b9453e22b (patch)
treeb49cd2fe7249fe979846f53e782388572a296d24
parenta94a2062af97f634f8192208a59f1656d1af680f (diff)
Fix crash in resource load
(cherry picked from commit 047671df0f6a7a300b83f36b5d6110a8165b0dfd)
-rw-r--r--core/io/resource_loader.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp
index c47f297a72..d0448e86fc 100644
--- a/core/io/resource_loader.cpp
+++ b/core/io/resource_loader.cpp
@@ -492,13 +492,21 @@ Ref<Resource> ResourceLoader::load_threaded_get(const String &p_path, Error *r_e
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));
}
+ bool still_valid = true;
+ bool was_thread = load_task.thread;
do {
load_task.cond_var->wait(thread_load_lock);
+ if (!thread_load_tasks.has(local_path)) { //may have been erased during unlock and this was always an invalid call
+ still_valid = false;
+ break;
+ }
} while (load_task.cond_var); // In case of spurious wakeup.
- thread_suspended_count--;
+ if (was_thread) {
+ thread_suspended_count--;
+ }
- if (!thread_load_tasks.has(local_path)) { //may have been erased during unlock and this was always an invalid call
+ if (!still_valid) {
if (r_error) {
*r_error = ERR_INVALID_PARAMETER;
}