You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2026-01-06 19:41:11 +00:00
Remake resource thread safety and API
* Ensures thread safety when resources are destroyed. * Simplified API by always forcing `ResourceCache::get_ref`, which needs less hacks and is fully thread safe. * Removed RWLock for resources because its not possible to use for the new logic. Should not be a problem. Supersedes #57533
This commit is contained in:
@@ -528,9 +528,9 @@ Error ResourceLoaderText::load() {
|
||||
|
||||
if (cache_mode == ResourceFormatLoader::CACHE_MODE_REPLACE && ResourceCache::has(path)) {
|
||||
//reuse existing
|
||||
Resource *r = ResourceCache::get(path);
|
||||
if (r && r->get_class() == type) {
|
||||
res = Ref<Resource>(r);
|
||||
Ref<Resource> cache = ResourceCache::get_ref(path);
|
||||
if (cache.is_valid() && cache->get_class() == type) {
|
||||
res = cache;
|
||||
res->reset_state();
|
||||
do_assign = true;
|
||||
}
|
||||
@@ -539,10 +539,10 @@ Error ResourceLoaderText::load() {
|
||||
MissingResource *missing_resource = nullptr;
|
||||
|
||||
if (res.is_null()) { //not reuse
|
||||
if (cache_mode != ResourceFormatLoader::CACHE_MODE_IGNORE && ResourceCache::has(path)) { //only if it doesn't exist
|
||||
Ref<Resource> cache = ResourceCache::get_ref(path);
|
||||
if (cache_mode != ResourceFormatLoader::CACHE_MODE_IGNORE && cache.is_valid()) { //only if it doesn't exist
|
||||
//cached, do not assign
|
||||
Resource *r = ResourceCache::get(path);
|
||||
res = Ref<Resource>(r);
|
||||
res = cache;
|
||||
} else {
|
||||
//create
|
||||
|
||||
@@ -652,12 +652,10 @@ Error ResourceLoaderText::load() {
|
||||
return error;
|
||||
}
|
||||
|
||||
if (cache_mode == ResourceFormatLoader::CACHE_MODE_REPLACE && ResourceCache::has(local_path)) {
|
||||
Resource *r = ResourceCache::get(local_path);
|
||||
if (r->get_class() == res_type) {
|
||||
r->reset_state();
|
||||
resource = Ref<Resource>(r);
|
||||
}
|
||||
Ref<Resource> cache = ResourceCache::get_ref(local_path);
|
||||
if (cache_mode == ResourceFormatLoader::CACHE_MODE_REPLACE && cache.is_valid() && cache->get_class() == res_type) {
|
||||
cache->reset_state();
|
||||
resource = cache;
|
||||
}
|
||||
|
||||
MissingResource *missing_resource = nullptr;
|
||||
|
||||
Reference in New Issue
Block a user