resource.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. /**************************************************************************/
  2. /* resource.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "resource.h"
  31. #include "core/core_string_names.h"
  32. #include "core/io/file_access.h"
  33. #include "core/io/resource_loader.h"
  34. #include "core/math/math_funcs.h"
  35. #include "core/object/script_language.h"
  36. #include "core/os/os.h"
  37. #include "scene/main/node.h" //only so casting works
  38. #include <stdio.h>
  39. void Resource::emit_changed() {
  40. emit_signal(CoreStringNames::get_singleton()->changed);
  41. }
  42. void Resource::_resource_path_changed() {
  43. }
  44. void Resource::set_path(const String &p_path, bool p_take_over) {
  45. if (path_cache == p_path) {
  46. return;
  47. }
  48. if (p_path.is_empty()) {
  49. p_take_over = false; // Can't take over an empty path
  50. }
  51. ResourceCache::lock.lock();
  52. if (!path_cache.is_empty()) {
  53. ResourceCache::resources.erase(path_cache);
  54. }
  55. path_cache = "";
  56. Ref<Resource> existing = ResourceCache::get_ref(p_path);
  57. if (existing.is_valid()) {
  58. if (p_take_over) {
  59. existing->path_cache = String();
  60. ResourceCache::resources.erase(p_path);
  61. } else {
  62. ResourceCache::lock.unlock();
  63. ERR_FAIL_MSG("Another resource is loaded from path '" + p_path + "' (possible cyclic resource inclusion).");
  64. }
  65. }
  66. path_cache = p_path;
  67. if (!path_cache.is_empty()) {
  68. ResourceCache::resources[path_cache] = this;
  69. }
  70. ResourceCache::lock.unlock();
  71. _resource_path_changed();
  72. }
  73. String Resource::get_path() const {
  74. return path_cache;
  75. }
  76. void Resource::set_path_cache(const String &p_path) {
  77. path_cache = p_path;
  78. }
  79. String Resource::generate_scene_unique_id() {
  80. // Generate a unique enough hash, but still user-readable.
  81. // If it's not unique it does not matter because the saver will try again.
  82. OS::DateTime dt = OS::get_singleton()->get_datetime();
  83. uint32_t hash = hash_murmur3_one_32(OS::get_singleton()->get_ticks_usec());
  84. hash = hash_murmur3_one_32(dt.year, hash);
  85. hash = hash_murmur3_one_32(dt.month, hash);
  86. hash = hash_murmur3_one_32(dt.day, hash);
  87. hash = hash_murmur3_one_32(dt.hour, hash);
  88. hash = hash_murmur3_one_32(dt.minute, hash);
  89. hash = hash_murmur3_one_32(dt.second, hash);
  90. hash = hash_murmur3_one_32(Math::rand(), hash);
  91. static constexpr uint32_t characters = 5;
  92. static constexpr uint32_t char_count = ('z' - 'a');
  93. static constexpr uint32_t base = char_count + ('9' - '0');
  94. String id;
  95. for (uint32_t i = 0; i < characters; i++) {
  96. uint32_t c = hash % base;
  97. if (c < char_count) {
  98. id += String::chr('a' + c);
  99. } else {
  100. id += String::chr('0' + (c - char_count));
  101. }
  102. hash /= base;
  103. }
  104. return id;
  105. }
  106. void Resource::set_scene_unique_id(const String &p_id) {
  107. scene_unique_id = p_id;
  108. }
  109. String Resource::get_scene_unique_id() const {
  110. return scene_unique_id;
  111. }
  112. void Resource::set_name(const String &p_name) {
  113. name = p_name;
  114. emit_changed();
  115. }
  116. String Resource::get_name() const {
  117. return name;
  118. }
  119. void Resource::update_configuration_warning() {
  120. if (_update_configuration_warning) {
  121. _update_configuration_warning();
  122. }
  123. }
  124. bool Resource::editor_can_reload_from_file() {
  125. return true; //by default yes
  126. }
  127. void Resource::connect_changed(const Callable &p_callable, uint32_t p_flags) {
  128. if (!is_connected(CoreStringNames::get_singleton()->changed, p_callable) || p_flags & CONNECT_REFERENCE_COUNTED) {
  129. connect(CoreStringNames::get_singleton()->changed, p_callable, p_flags);
  130. }
  131. }
  132. void Resource::disconnect_changed(const Callable &p_callable) {
  133. if (is_connected(CoreStringNames::get_singleton()->changed, p_callable)) {
  134. disconnect(CoreStringNames::get_singleton()->changed, p_callable);
  135. }
  136. }
  137. void Resource::reset_state() {
  138. }
  139. Error Resource::copy_from(const Ref<Resource> &p_resource) {
  140. ERR_FAIL_COND_V(p_resource.is_null(), ERR_INVALID_PARAMETER);
  141. if (get_class() != p_resource->get_class()) {
  142. return ERR_INVALID_PARAMETER;
  143. }
  144. reset_state(); // May want to reset state.
  145. List<PropertyInfo> pi;
  146. p_resource->get_property_list(&pi);
  147. for (const PropertyInfo &E : pi) {
  148. if (!(E.usage & PROPERTY_USAGE_STORAGE)) {
  149. continue;
  150. }
  151. if (E.name == "resource_path") {
  152. continue; //do not change path
  153. }
  154. set(E.name, p_resource->get(E.name));
  155. }
  156. return OK;
  157. }
  158. void Resource::reload_from_file() {
  159. String path = get_path();
  160. if (!path.is_resource_file()) {
  161. return;
  162. }
  163. Ref<Resource> s = ResourceLoader::load(ResourceLoader::path_remap(path), get_class(), ResourceFormatLoader::CACHE_MODE_IGNORE);
  164. if (!s.is_valid()) {
  165. return;
  166. }
  167. copy_from(s);
  168. }
  169. void Resource::_dupe_sub_resources(Variant &r_variant, Node *p_for_scene, HashMap<Ref<Resource>, Ref<Resource>> &p_remap_cache) {
  170. switch (r_variant.get_type()) {
  171. case Variant::ARRAY: {
  172. Array a = r_variant;
  173. for (int i = 0; i < a.size(); i++) {
  174. _dupe_sub_resources(a[i], p_for_scene, p_remap_cache);
  175. }
  176. } break;
  177. case Variant::DICTIONARY: {
  178. Dictionary d = r_variant;
  179. List<Variant> keys;
  180. d.get_key_list(&keys);
  181. for (Variant &k : keys) {
  182. if (k.get_type() == Variant::OBJECT) {
  183. // Replace in dictionary key.
  184. Ref<Resource> sr = k;
  185. if (sr.is_valid() && sr->is_local_to_scene()) {
  186. if (p_remap_cache.has(sr)) {
  187. d[p_remap_cache[sr]] = d[k];
  188. d.erase(k);
  189. } else {
  190. Ref<Resource> dupe = sr->duplicate_for_local_scene(p_for_scene, p_remap_cache);
  191. d[dupe] = d[k];
  192. d.erase(k);
  193. p_remap_cache[sr] = dupe;
  194. }
  195. }
  196. } else {
  197. _dupe_sub_resources(k, p_for_scene, p_remap_cache);
  198. }
  199. _dupe_sub_resources(d[k], p_for_scene, p_remap_cache);
  200. }
  201. } break;
  202. case Variant::OBJECT: {
  203. Ref<Resource> sr = r_variant;
  204. if (sr.is_valid() && sr->is_local_to_scene()) {
  205. if (p_remap_cache.has(sr)) {
  206. r_variant = p_remap_cache[sr];
  207. } else {
  208. Ref<Resource> dupe = sr->duplicate_for_local_scene(p_for_scene, p_remap_cache);
  209. r_variant = dupe;
  210. p_remap_cache[sr] = dupe;
  211. }
  212. }
  213. } break;
  214. default: {
  215. }
  216. }
  217. }
  218. Ref<Resource> Resource::duplicate_for_local_scene(Node *p_for_scene, HashMap<Ref<Resource>, Ref<Resource>> &p_remap_cache) {
  219. List<PropertyInfo> plist;
  220. get_property_list(&plist);
  221. Ref<Resource> r = Object::cast_to<Resource>(ClassDB::instantiate(get_class()));
  222. ERR_FAIL_COND_V(r.is_null(), Ref<Resource>());
  223. r->local_scene = p_for_scene;
  224. for (const PropertyInfo &E : plist) {
  225. if (!(E.usage & PROPERTY_USAGE_STORAGE)) {
  226. continue;
  227. }
  228. Variant p = get(E.name).duplicate(true);
  229. _dupe_sub_resources(p, p_for_scene, p_remap_cache);
  230. r->set(E.name, p);
  231. }
  232. return r;
  233. }
  234. void Resource::_find_sub_resources(const Variant &p_variant, HashSet<Ref<Resource>> &p_resources_found) {
  235. switch (p_variant.get_type()) {
  236. case Variant::ARRAY: {
  237. Array a = p_variant;
  238. for (int i = 0; i < a.size(); i++) {
  239. _find_sub_resources(a[i], p_resources_found);
  240. }
  241. } break;
  242. case Variant::DICTIONARY: {
  243. Dictionary d = p_variant;
  244. List<Variant> keys;
  245. d.get_key_list(&keys);
  246. for (const Variant &k : keys) {
  247. _find_sub_resources(k, p_resources_found);
  248. _find_sub_resources(d[k], p_resources_found);
  249. }
  250. } break;
  251. case Variant::OBJECT: {
  252. Ref<Resource> r = p_variant;
  253. if (r.is_valid()) {
  254. p_resources_found.insert(r);
  255. }
  256. } break;
  257. default: {
  258. }
  259. }
  260. }
  261. void Resource::configure_for_local_scene(Node *p_for_scene, HashMap<Ref<Resource>, Ref<Resource>> &p_remap_cache) {
  262. List<PropertyInfo> plist;
  263. get_property_list(&plist);
  264. reset_local_to_scene();
  265. local_scene = p_for_scene;
  266. for (const PropertyInfo &E : plist) {
  267. if (!(E.usage & PROPERTY_USAGE_STORAGE)) {
  268. continue;
  269. }
  270. Variant p = get(E.name);
  271. HashSet<Ref<Resource>> sub_resources;
  272. _find_sub_resources(p, sub_resources);
  273. for (Ref<Resource> sr : sub_resources) {
  274. if (sr->is_local_to_scene()) {
  275. if (!p_remap_cache.has(sr)) {
  276. sr->configure_for_local_scene(p_for_scene, p_remap_cache);
  277. p_remap_cache[sr] = sr;
  278. }
  279. }
  280. }
  281. }
  282. }
  283. Ref<Resource> Resource::duplicate(bool p_subresources) const {
  284. List<PropertyInfo> plist;
  285. get_property_list(&plist);
  286. Ref<Resource> r = static_cast<Resource *>(ClassDB::instantiate(get_class()));
  287. ERR_FAIL_COND_V(r.is_null(), Ref<Resource>());
  288. for (const PropertyInfo &E : plist) {
  289. if (!(E.usage & PROPERTY_USAGE_STORAGE)) {
  290. continue;
  291. }
  292. Variant p = get(E.name);
  293. switch (p.get_type()) {
  294. case Variant::Type::DICTIONARY:
  295. case Variant::Type::ARRAY:
  296. case Variant::Type::PACKED_BYTE_ARRAY:
  297. case Variant::Type::PACKED_COLOR_ARRAY:
  298. case Variant::Type::PACKED_INT32_ARRAY:
  299. case Variant::Type::PACKED_INT64_ARRAY:
  300. case Variant::Type::PACKED_FLOAT32_ARRAY:
  301. case Variant::Type::PACKED_FLOAT64_ARRAY:
  302. case Variant::Type::PACKED_STRING_ARRAY:
  303. case Variant::Type::PACKED_VECTOR2_ARRAY:
  304. case Variant::Type::PACKED_VECTOR3_ARRAY: {
  305. r->set(E.name, p.duplicate(p_subresources));
  306. } break;
  307. case Variant::Type::OBJECT: {
  308. if (!(E.usage & PROPERTY_USAGE_NEVER_DUPLICATE) && (p_subresources || (E.usage & PROPERTY_USAGE_ALWAYS_DUPLICATE))) {
  309. Ref<Resource> sr = p;
  310. if (sr.is_valid()) {
  311. r->set(E.name, sr->duplicate(p_subresources));
  312. }
  313. } else {
  314. r->set(E.name, p);
  315. }
  316. } break;
  317. default: {
  318. r->set(E.name, p);
  319. }
  320. }
  321. }
  322. return r;
  323. }
  324. void Resource::_set_path(const String &p_path) {
  325. set_path(p_path, false);
  326. }
  327. void Resource::_take_over_path(const String &p_path) {
  328. set_path(p_path, true);
  329. }
  330. RID Resource::get_rid() const {
  331. if (get_script_instance()) {
  332. Callable::CallError ce;
  333. RID ret = get_script_instance()->callp(SNAME("_get_rid"), nullptr, 0, ce);
  334. if (ce.error == Callable::CallError::CALL_OK && ret.is_valid()) {
  335. return ret;
  336. }
  337. }
  338. if (_get_extension() && _get_extension()->get_rid) {
  339. RID ret;
  340. ret.from_uint64(_get_extension()->get_rid(_get_extension_instance()));
  341. if (ret.is_valid()) {
  342. return ret;
  343. }
  344. }
  345. return RID();
  346. }
  347. #ifdef TOOLS_ENABLED
  348. uint32_t Resource::hash_edited_version() const {
  349. uint32_t hash = hash_murmur3_one_32(get_edited_version());
  350. List<PropertyInfo> plist;
  351. get_property_list(&plist);
  352. for (const PropertyInfo &E : plist) {
  353. if (E.usage & PROPERTY_USAGE_STORAGE && E.type == Variant::OBJECT && E.hint == PROPERTY_HINT_RESOURCE_TYPE) {
  354. Ref<Resource> res = get(E.name);
  355. if (res.is_valid()) {
  356. hash = hash_murmur3_one_32(res->hash_edited_version(), hash);
  357. }
  358. }
  359. }
  360. return hash;
  361. }
  362. #endif
  363. void Resource::set_local_to_scene(bool p_enable) {
  364. local_to_scene = p_enable;
  365. }
  366. bool Resource::is_local_to_scene() const {
  367. return local_to_scene;
  368. }
  369. Node *Resource::get_local_scene() const {
  370. if (local_scene) {
  371. return local_scene;
  372. }
  373. if (_get_local_scene_func) {
  374. return _get_local_scene_func();
  375. }
  376. return nullptr;
  377. }
  378. void Resource::setup_local_to_scene() {
  379. emit_signal(SNAME("setup_local_to_scene_requested"));
  380. GDVIRTUAL_CALL(_setup_local_to_scene);
  381. }
  382. void Resource::reset_local_to_scene() {
  383. // Restores the state as if setup_local_to_scene() hadn't been called.
  384. }
  385. Node *(*Resource::_get_local_scene_func)() = nullptr;
  386. void (*Resource::_update_configuration_warning)() = nullptr;
  387. void Resource::set_as_translation_remapped(bool p_remapped) {
  388. if (remapped_list.in_list() == p_remapped) {
  389. return;
  390. }
  391. ResourceCache::lock.lock();
  392. if (p_remapped) {
  393. ResourceLoader::remapped_list.add(&remapped_list);
  394. } else {
  395. ResourceLoader::remapped_list.remove(&remapped_list);
  396. }
  397. ResourceCache::lock.unlock();
  398. }
  399. #ifdef TOOLS_ENABLED
  400. //helps keep IDs same number when loading/saving scenes. -1 clears ID and it Returns -1 when no id stored
  401. void Resource::set_id_for_path(const String &p_path, const String &p_id) {
  402. if (p_id.is_empty()) {
  403. ResourceCache::path_cache_lock.write_lock();
  404. ResourceCache::resource_path_cache[p_path].erase(get_path());
  405. ResourceCache::path_cache_lock.write_unlock();
  406. } else {
  407. ResourceCache::path_cache_lock.write_lock();
  408. ResourceCache::resource_path_cache[p_path][get_path()] = p_id;
  409. ResourceCache::path_cache_lock.write_unlock();
  410. }
  411. }
  412. String Resource::get_id_for_path(const String &p_path) const {
  413. ResourceCache::path_cache_lock.read_lock();
  414. if (ResourceCache::resource_path_cache[p_path].has(get_path())) {
  415. String result = ResourceCache::resource_path_cache[p_path][get_path()];
  416. ResourceCache::path_cache_lock.read_unlock();
  417. return result;
  418. } else {
  419. ResourceCache::path_cache_lock.read_unlock();
  420. return "";
  421. }
  422. }
  423. #endif
  424. void Resource::_bind_methods() {
  425. ClassDB::bind_method(D_METHOD("set_path", "path"), &Resource::_set_path);
  426. ClassDB::bind_method(D_METHOD("take_over_path", "path"), &Resource::_take_over_path);
  427. ClassDB::bind_method(D_METHOD("get_path"), &Resource::get_path);
  428. ClassDB::bind_method(D_METHOD("set_name", "name"), &Resource::set_name);
  429. ClassDB::bind_method(D_METHOD("get_name"), &Resource::get_name);
  430. ClassDB::bind_method(D_METHOD("get_rid"), &Resource::get_rid);
  431. ClassDB::bind_method(D_METHOD("set_local_to_scene", "enable"), &Resource::set_local_to_scene);
  432. ClassDB::bind_method(D_METHOD("is_local_to_scene"), &Resource::is_local_to_scene);
  433. ClassDB::bind_method(D_METHOD("get_local_scene"), &Resource::get_local_scene);
  434. ClassDB::bind_method(D_METHOD("setup_local_to_scene"), &Resource::setup_local_to_scene);
  435. ClassDB::bind_method(D_METHOD("emit_changed"), &Resource::emit_changed);
  436. ClassDB::bind_method(D_METHOD("duplicate", "subresources"), &Resource::duplicate, DEFVAL(false));
  437. ADD_SIGNAL(MethodInfo("changed"));
  438. ADD_SIGNAL(MethodInfo("setup_local_to_scene_requested"));
  439. ADD_GROUP("Resource", "resource_");
  440. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "resource_local_to_scene"), "set_local_to_scene", "is_local_to_scene");
  441. ADD_PROPERTY(PropertyInfo(Variant::STRING, "resource_path", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_path", "get_path");
  442. ADD_PROPERTY(PropertyInfo(Variant::STRING, "resource_name"), "set_name", "get_name");
  443. MethodInfo get_rid_bind("_get_rid");
  444. get_rid_bind.return_val.type = Variant::RID;
  445. ::ClassDB::add_virtual_method(get_class_static(), get_rid_bind, true, Vector<String>(), true);
  446. GDVIRTUAL_BIND(_setup_local_to_scene);
  447. }
  448. Resource::Resource() :
  449. remapped_list(this) {}
  450. Resource::~Resource() {
  451. if (!path_cache.is_empty()) {
  452. ResourceCache::lock.lock();
  453. ResourceCache::resources.erase(path_cache);
  454. ResourceCache::lock.unlock();
  455. }
  456. }
  457. HashMap<String, Resource *> ResourceCache::resources;
  458. #ifdef TOOLS_ENABLED
  459. HashMap<String, HashMap<String, String>> ResourceCache::resource_path_cache;
  460. #endif
  461. Mutex ResourceCache::lock;
  462. #ifdef TOOLS_ENABLED
  463. RWLock ResourceCache::path_cache_lock;
  464. #endif
  465. void ResourceCache::clear() {
  466. if (!resources.is_empty()) {
  467. if (OS::get_singleton()->is_stdout_verbose()) {
  468. ERR_PRINT(vformat("%d resources still in use at exit.", resources.size()));
  469. for (const KeyValue<String, Resource *> &E : resources) {
  470. print_line(vformat("Resource still in use: %s (%s)", E.key, E.value->get_class()));
  471. }
  472. } else {
  473. ERR_PRINT(vformat("%d resources still in use at exit (run with --verbose for details).", resources.size()));
  474. }
  475. }
  476. resources.clear();
  477. }
  478. bool ResourceCache::has(const String &p_path) {
  479. lock.lock();
  480. Resource **res = resources.getptr(p_path);
  481. if (res && (*res)->get_reference_count() == 0) {
  482. // This resource is in the process of being deleted, ignore its existence.
  483. (*res)->path_cache = String();
  484. resources.erase(p_path);
  485. res = nullptr;
  486. }
  487. lock.unlock();
  488. if (!res) {
  489. return false;
  490. }
  491. return true;
  492. }
  493. Ref<Resource> ResourceCache::get_ref(const String &p_path) {
  494. Ref<Resource> ref;
  495. lock.lock();
  496. Resource **res = resources.getptr(p_path);
  497. if (res) {
  498. ref = Ref<Resource>(*res);
  499. }
  500. if (res && !ref.is_valid()) {
  501. // This resource is in the process of being deleted, ignore its existence
  502. (*res)->path_cache = String();
  503. resources.erase(p_path);
  504. res = nullptr;
  505. }
  506. lock.unlock();
  507. return ref;
  508. }
  509. void ResourceCache::get_cached_resources(List<Ref<Resource>> *p_resources) {
  510. lock.lock();
  511. LocalVector<String> to_remove;
  512. for (KeyValue<String, Resource *> &E : resources) {
  513. Ref<Resource> ref = Ref<Resource>(E.value);
  514. if (!ref.is_valid()) {
  515. // This resource is in the process of being deleted, ignore its existence
  516. E.value->path_cache = String();
  517. to_remove.push_back(E.key);
  518. continue;
  519. }
  520. p_resources->push_back(ref);
  521. }
  522. for (const String &E : to_remove) {
  523. resources.erase(E);
  524. }
  525. lock.unlock();
  526. }
  527. int ResourceCache::get_cached_resource_count() {
  528. lock.lock();
  529. int rc = resources.size();
  530. lock.unlock();
  531. return rc;
  532. }