Merge pull request #101752 from MTareqAzim/fix-resource-loader-cache-uid

Fix ResourceLoader.has_cached() and ResourceLoader.get_cached_ref() not handling UIDs.
This commit is contained in:
Thaddeus Crews 2025-01-22 16:32:24 -06:00
commit 376b1c9de9
No known key found for this signature in database
GPG Key ID: 62181B86FE9E5D84
3 changed files with 10 additions and 3 deletions

View File

@ -113,12 +113,12 @@ PackedStringArray ResourceLoader::get_dependencies(const String &p_path) {
}
bool ResourceLoader::has_cached(const String &p_path) {
String local_path = ProjectSettings::get_singleton()->localize_path(p_path);
String local_path = ::ResourceLoader::_validate_local_path(p_path);
return ResourceCache::has(local_path);
}
Ref<Resource> ResourceLoader::get_cached_ref(const String &p_path) {
String local_path = ProjectSettings::get_singleton()->localize_path(p_path);
String local_path = ::ResourceLoader::_validate_local_path(p_path);
return ResourceCache::get_ref(local_path);
}

View File

@ -495,7 +495,7 @@ void ResourceLoader::_run_load_task(void *p_userdata) {
curr_load_task = curr_load_task_backup;
}
static String _validate_local_path(const String &p_path) {
String ResourceLoader::_validate_local_path(const String &p_path) {
ResourceUID::ID uid = ResourceUID::get_singleton()->text_to_id(p_path);
if (uid != ResourceUID::INVALID_ID) {
return ResourceUID::get_singleton()->get_id_path(uid);

View File

@ -36,6 +36,10 @@
#include "core/object/worker_thread_pool.h"
#include "core/os/thread.h"
namespace core_bind {
class ResourceLoader;
}
class ConditionVariable;
template <int Tag>
@ -101,6 +105,7 @@ typedef void (*ResourceLoadedCallback)(Ref<Resource> p_resource, const String &p
class ResourceLoader {
friend class LoadToken;
friend class core_bind::ResourceLoader;
enum {
MAX_LOADERS = 64
@ -217,6 +222,8 @@ private:
static bool _ensure_load_progress();
static String _validate_local_path(const String &p_path);
public:
static Error load_threaded_request(const String &p_path, const String &p_type_hint = "", bool p_use_sub_threads = false, ResourceFormatLoader::CacheMode p_cache_mode = ResourceFormatLoader::CACHE_MODE_REUSE);
static ThreadLoadStatus load_threaded_get_status(const String &p_path, float *r_progress = nullptr);