From 9014cdb59699bf5701298126cee2fe4b1766995a Mon Sep 17 00:00:00 2001 From: Tareq Anuar Date: Sat, 18 Jan 2025 19:46:03 +0800 Subject: [PATCH] Fix ResourceLoader.has_cached() and ResourceLoader.get_cached_ref() not handling UIDs. --- core/core_bind.cpp | 4 ++-- core/io/resource_loader.cpp | 2 +- core/io/resource_loader.h | 7 +++++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/core/core_bind.cpp b/core/core_bind.cpp index 6974d98234c..acd589783ec 100644 --- a/core/core_bind.cpp +++ b/core/core_bind.cpp @@ -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 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); } diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index 8f873d859b6..7cc91ef4318 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -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); diff --git a/core/io/resource_loader.h b/core/io/resource_loader.h index f933e88b23b..56052b6a6fc 100644 --- a/core/io/resource_loader.h +++ b/core/io/resource_loader.h @@ -36,6 +36,10 @@ #include "core/object/worker_thread_pool.h" #include "core/os/thread.h" +namespace core_bind { +class ResourceLoader; +} + class ConditionVariable; template @@ -101,6 +105,7 @@ typedef void (*ResourceLoadedCallback)(Ref 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);