summaryrefslogtreecommitdiffstats
path: root/core/io/resource_loader.cpp
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-02-13 23:43:18 +0100
committerRémi Verschelde <rverschelde@gmail.com>2024-02-13 23:43:18 +0100
commitdc99c8d4a4e2456da2988dac078e3085d2034664 (patch)
tree160b828d58d7baef2593858edf85c721cf2976d6 /core/io/resource_loader.cpp
parent921b656f33676336dccfe15baca63853222ecfd7 (diff)
parent2e09985c0d2579d32238272b0dd3c70ef4821430 (diff)
downloadredot-engine-dc99c8d4a4e2456da2988dac078e3085d2034664.tar.gz
Merge pull request #87008 from KoBeWi/cache_mode_replace_fixes²
Fix² behavior of ResourceFormatLoader `CACHE_MODE_REPLACE`
Diffstat (limited to 'core/io/resource_loader.cpp')
-rw-r--r--core/io/resource_loader.cpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp
index 2fb3bda87d..64b47ad19d 100644
--- a/core/io/resource_loader.cpp
+++ b/core/io/resource_loader.cpp
@@ -341,7 +341,15 @@ void ResourceLoader::_thread_load_function(void *p_userdata) {
if (load_task.resource.is_valid()) {
if (load_task.cache_mode != ResourceFormatLoader::CACHE_MODE_IGNORE) {
- load_task.resource->set_path(load_task.local_path);
+ if (load_task.cache_mode == ResourceFormatLoader::CACHE_MODE_REPLACE) {
+ Ref<Resource> old_res = ResourceCache::get_ref(load_task.local_path);
+ if (old_res.is_valid() && old_res != load_task.resource) {
+ // If resource is already loaded, only replace its data, to avoid existing invalidating instances.
+ old_res->copy_from(load_task.resource);
+ load_task.resource = old_res;
+ }
+ }
+ load_task.resource->set_path(load_task.local_path, load_task.cache_mode == ResourceFormatLoader::CACHE_MODE_REPLACE);
} else if (!load_task.local_path.is_resource_file()) {
load_task.resource->set_path_cache(load_task.local_path);
}
@@ -362,6 +370,17 @@ void ResourceLoader::_thread_load_function(void *p_userdata) {
if (_loaded_callback) {
_loaded_callback(load_task.resource, load_task.local_path);
}
+ } else if (load_task.cache_mode != ResourceFormatLoader::CACHE_MODE_IGNORE) {
+ Ref<Resource> existing = ResourceCache::get_ref(load_task.local_path);
+ if (existing.is_valid()) {
+ load_task.resource = existing;
+ load_task.status = THREAD_LOAD_LOADED;
+ load_task.progress = 1.0;
+
+ if (_loaded_callback) {
+ _loaded_callback(load_task.resource, load_task.local_path);
+ }
+ }
}
thread_load_mutex.unlock();
@@ -464,7 +483,7 @@ Ref<ResourceLoader::LoadToken> ResourceLoader::_load_start(const String &p_path,
load_task.type_hint = p_type_hint;
load_task.cache_mode = p_cache_mode;
load_task.use_sub_threads = p_thread_mode == LOAD_THREAD_DISTRIBUTE;
- if (p_cache_mode != ResourceFormatLoader::CACHE_MODE_IGNORE) {
+ if (p_cache_mode == ResourceFormatLoader::CACHE_MODE_REUSE) {
Ref<Resource> existing = ResourceCache::get_ref(local_path);
if (existing.is_valid()) {
//referencing is fine