Skip to content

Commit 28a7a95

Browse files
committed
ResourceLoader: Fix sync issues with error reporting
This is about not letting the resource format loader set the error code directly on the task anymore. Instead, it's stored locally and assigned only when it is right to do so. Otherwise, other tasks may see an error code in the current one before it's state having transitioned to errored. While this, besides the technically true data race, may not be a problem in practice, it causes surprising situations during debugging as it breaks assumptions.
1 parent 5b5cdf2 commit 28a7a95

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

core/io/resource_loader.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,8 @@ void ResourceLoader::_thread_load_function(void *p_userdata) {
319319
}
320320
// --
321321

322-
Ref<Resource> res = _load(load_task.remapped_path, load_task.remapped_path != load_task.local_path ? load_task.local_path : String(), load_task.type_hint, load_task.cache_mode, &load_task.error, load_task.use_sub_threads, &load_task.progress);
322+
Error load_err = OK;
323+
Ref<Resource> res = _load(load_task.remapped_path, load_task.remapped_path != load_task.local_path ? load_task.local_path : String(), load_task.type_hint, load_task.cache_mode, &load_err, load_task.use_sub_threads, &load_task.progress);
323324
if (MessageQueue::get_singleton() != MessageQueue::get_main_singleton()) {
324325
MessageQueue::get_singleton()->flush();
325326
}
@@ -328,7 +329,8 @@ void ResourceLoader::_thread_load_function(void *p_userdata) {
328329

329330
load_task.resource = res;
330331

331-
load_task.progress = 1.0; //it was fully loaded at this point, so force progress to 1.0
332+
load_task.progress = 1.0; // It was fully loaded at this point, so force progress to 1.0.
333+
load_task.error = load_err;
332334
if (load_task.error != OK) {
333335
load_task.status = THREAD_LOAD_FAILED;
334336
} else {

0 commit comments

Comments
 (0)