Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResourceLoader: Let resource setup late steps invoke loading in turn #94910

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion core/io/resource_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,14 @@ void ResourceLoader::_thread_load_function(void *p_userdata) {

bool ignoring = load_task.cache_mode == ResourceFormatLoader::CACHE_MODE_IGNORE || load_task.cache_mode == ResourceFormatLoader::CACHE_MODE_IGNORE_DEEP;
bool replacing = load_task.cache_mode == ResourceFormatLoader::CACHE_MODE_REPLACE || load_task.cache_mode == ResourceFormatLoader::CACHE_MODE_REPLACE_DEEP;
bool unlock_pending = true;
if (load_task.resource.is_valid()) {
// From now on, no critical section needed as no one will write to the task anymore.
// Moreover, the mutex being unlocked is a requirement if some of the calls below
// that set the resource up invoke code that in turn requests resource loading.
thread_load_mutex.unlock();
unlock_pending = false;

if (!ignoring) {
if (replacing) {
Ref<Resource> old_res = ResourceCache::get_ref(load_task.local_path);
Expand Down Expand Up @@ -383,13 +390,18 @@ void ResourceLoader::_thread_load_function(void *p_userdata) {
load_task.status = THREAD_LOAD_LOADED;
load_task.progress = 1.0;

thread_load_mutex.unlock();
unlock_pending = false;

if (_loaded_callback) {
_loaded_callback(load_task.resource, load_task.local_path);
}
}
}

thread_load_mutex.unlock();
if (unlock_pending) {
thread_load_mutex.unlock();
}

if (load_nesting == 0) {
if (own_mq_override) {
Expand Down
Loading