From c586835541cfac68c3d56f91d206f1f37103756c Mon Sep 17 00:00:00 2001 From: voidedWarranties Date: Sun, 19 Feb 2023 20:15:22 -0800 Subject: [PATCH] Make `ResourceCache::get_cached_resources` thread-safe --- core/io/resource.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/core/io/resource.cpp b/core/io/resource.cpp index 4abcbffb612..6b8ec8d5f66 100644 --- a/core/io/resource.cpp +++ b/core/io/resource.cpp @@ -542,9 +542,26 @@ Ref ResourceCache::get_ref(const String &p_path) { void ResourceCache::get_cached_resources(List> *p_resources) { lock.lock(); + + LocalVector to_remove; + for (KeyValue &E : resources) { - p_resources->push_back(Ref(E.value)); + Ref ref = Ref(E.value); + + if (!ref.is_valid()) { + // This resource is in the process of being deleted, ignore its existence + E.value->path_cache = String(); + to_remove.push_back(E.key); + continue; + } + + p_resources->push_back(ref); } + + for (const String &E : to_remove) { + resources.erase(E); + } + lock.unlock(); }