summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2022-12-08 09:51:38 +0100
committerRémi Verschelde <rverschelde@gmail.com>2022-12-08 09:51:38 +0100
commitb86a874e029b28d6d7d7c684d8a712d035c6916e (patch)
treebdcd659482630bcd7fe6eb90d6e6b57b4b016601
parentcf093f8e47f9508565cdc52bb724dbdb3d548e90 (diff)
parent4a16b8630e0fc73fe3178bf4828f22e07aec5aa0 (diff)
Merge pull request #69679 from adamscott/fix-resourceloader-thread_load_tasks-crash
Fix `ResourceLoader::thread_load_tasks` crash
-rw-r--r--core/io/resource_loader.cpp29
-rw-r--r--core/io/resource_loader.h2
-rw-r--r--main/main.cpp2
3 files changed, 33 insertions, 0 deletions
diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp
index 6219ea70e4..20445a8b03 100644
--- a/core/io/resource_loader.cpp
+++ b/core/io/resource_loader.cpp
@@ -923,6 +923,35 @@ void ResourceLoader::clear_translation_remaps() {
}
}
+void ResourceLoader::clear_thread_load_tasks() {
+ thread_load_mutex->lock();
+
+ for (KeyValue<String, ResourceLoader::ThreadLoadTask> &E : thread_load_tasks) {
+ switch (E.value.status) {
+ case ResourceLoader::ThreadLoadStatus::THREAD_LOAD_LOADED: {
+ E.value.resource = Ref<Resource>();
+ } break;
+
+ case ResourceLoader::ThreadLoadStatus::THREAD_LOAD_IN_PROGRESS: {
+ if (E.value.thread != nullptr) {
+ E.value.thread->wait_to_finish();
+ memdelete(E.value.thread);
+ E.value.thread = nullptr;
+ }
+ E.value.resource = Ref<Resource>();
+ } break;
+
+ case ResourceLoader::ThreadLoadStatus::THREAD_LOAD_FAILED:
+ default: {
+ // do nothing
+ }
+ }
+ }
+ thread_load_tasks.clear();
+
+ thread_load_mutex->unlock();
+}
+
void ResourceLoader::load_path_remaps() {
if (!ProjectSettings::get_singleton()->has_setting("path_remap/remapped_paths")) {
return;
diff --git a/core/io/resource_loader.h b/core/io/resource_loader.h
index 243670b2d0..af10098bd8 100644
--- a/core/io/resource_loader.h
+++ b/core/io/resource_loader.h
@@ -219,6 +219,8 @@ public:
static void load_translation_remaps();
static void clear_translation_remaps();
+ static void clear_thread_load_tasks();
+
static void set_load_callback(ResourceLoadedCallback p_callback);
static ResourceLoaderImport import;
diff --git a/main/main.cpp b/main/main.cpp
index 83703c55c2..dd33dec543 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -3328,6 +3328,8 @@ void Main::cleanup(bool p_force) {
ResourceLoader::clear_translation_remaps();
ResourceLoader::clear_path_remaps();
+ ResourceLoader::clear_thread_load_tasks();
+
ScriptServer::finish_languages();
// Sync pending commands that may have been queued from a different thread during ScriptServer finalization