Pārlūkot izejas kodu

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

Fix ResourceLoader.has_cached() and ResourceLoader.get_cached_ref() not handling UIDs.
Thaddeus Crews 6 mēneši atpakaļ
vecāks
revīzija
376b1c9de9
3 mainītis faili ar 10 papildinājumiem un 3 dzēšanām
  1. 2 2
      core/core_bind.cpp
  2. 1 1
      core/io/resource_loader.cpp
  3. 7 0
      core/io/resource_loader.h

+ 2 - 2
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<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);
 }
 

+ 1 - 1
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);

+ 7 - 0
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 <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);