summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2023-02-20 11:29:08 +0100
committerRémi Verschelde <rverschelde@gmail.com>2023-02-20 11:29:08 +0100
commit32a29977fbc030ad0d41b3b8eb3b165864cd5833 (patch)
treeff281ad6efde611a4cdb442eefa55185111de447
parent4cd2aec2f08324b1d5a2ecc87af028351d30a8f0 (diff)
parentc586835541cfac68c3d56f91d206f1f37103756c (diff)
Merge pull request #73616 from voidedWarranties/resourcecache_thread_safe
Make `ResourceCache::get_cached_resources` thread-safe
-rw-r--r--core/io/resource.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/core/io/resource.cpp b/core/io/resource.cpp
index 4abcbffb61..6b8ec8d5f6 100644
--- a/core/io/resource.cpp
+++ b/core/io/resource.cpp
@@ -542,9 +542,26 @@ Ref<Resource> ResourceCache::get_ref(const String &p_path) {
void ResourceCache::get_cached_resources(List<Ref<Resource>> *p_resources) {
lock.lock();
+
+ LocalVector<String> to_remove;
+
for (KeyValue<String, Resource *> &E : resources) {
- p_resources->push_back(Ref<Resource>(E.value));
+ Ref<Resource> ref = Ref<Resource>(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();
}