Skip to content

Commit 17ac9b3

Browse files
committed
ResourceLoader: Fix potential infinite recursion in progress reporting
1 parent 235a32a commit 17ac9b3

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

core/io/resource_loader.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,11 @@ Ref<ResourceLoader::LoadToken> ResourceLoader::_load_start(const String &p_path,
666666
float ResourceLoader::_dependency_get_progress(const String &p_path) {
667667
if (thread_load_tasks.has(p_path)) {
668668
ThreadLoadTask &load_task = thread_load_tasks[p_path];
669+
if (load_task.in_progress_check) {
670+
// Avoid cycles.
671+
return load_task.max_reported_progress;
672+
}
673+
load_task.in_progress_check = true;
669674
float current_progress = 0.0;
670675
int dep_count = load_task.sub_tasks.size();
671676
if (dep_count > 0) {
@@ -679,6 +684,7 @@ float ResourceLoader::_dependency_get_progress(const String &p_path) {
679684
current_progress = load_task.progress;
680685
}
681686
load_task.max_reported_progress = MAX(load_task.max_reported_progress, current_progress);
687+
load_task.in_progress_check = false;
682688
return load_task.max_reported_progress;
683689
} else {
684690
return 1.0; //assume finished loading it so it no longer exists

core/io/resource_loader.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,8 @@ class ResourceLoader {
176176
struct ThreadLoadTask {
177177
WorkerThreadPool::TaskID task_id = 0; // Used if run on a worker thread from the pool.
178178
Thread::ID thread_id = 0; // Used if running on an user thread (e.g., simple non-threaded load).
179-
bool awaited = false; // If it's in the pool, this helps not awaiting from more than one dependent thread.
180179
ConditionVariable *cond_var = nullptr; // In not in the worker pool or already awaiting, this is used as a secondary awaiting mechanism.
181180
uint32_t awaiters_count = 0;
182-
bool need_wait = true;
183181
LoadToken *load_token = nullptr;
184182
String local_path;
185183
String type_hint;
@@ -190,9 +188,15 @@ class ResourceLoader {
190188
ResourceFormatLoader::CacheMode cache_mode = ResourceFormatLoader::CACHE_MODE_REUSE;
191189
Error error = OK;
192190
Ref<Resource> resource;
193-
bool use_sub_threads = false;
194191
HashSet<String> sub_tasks;
195192

193+
struct {
194+
bool awaited = false; // If it's in the pool, this helps not awaiting from more than one dependent thread.
195+
bool need_wait = true;
196+
bool in_progress_check = false;
197+
bool use_sub_threads = false;
198+
};
199+
196200
struct ResourceChangedConnection {
197201
Resource *source = nullptr;
198202
Callable callable;

0 commit comments

Comments
 (0)