Sfoglia il codice sorgente

Merge pull request #69679 from adamscott/fix-resourceloader-thread_load_tasks-crash

Fix `ResourceLoader::thread_load_tasks` crash
Rémi Verschelde 2 anni fa
parent
commit
b86a874e02
3 ha cambiato i file con 33 aggiunte e 0 eliminazioni
  1. 29 0
      core/io/resource_loader.cpp
  2. 2 0
      core/io/resource_loader.h
  3. 2 0
      main/main.cpp

+ 29 - 0
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() {
 void ResourceLoader::load_path_remaps() {
 	if (!ProjectSettings::get_singleton()->has_setting("path_remap/remapped_paths")) {
 	if (!ProjectSettings::get_singleton()->has_setting("path_remap/remapped_paths")) {
 		return;
 		return;

+ 2 - 0
core/io/resource_loader.h

@@ -219,6 +219,8 @@ public:
 	static void load_translation_remaps();
 	static void load_translation_remaps();
 	static void clear_translation_remaps();
 	static void clear_translation_remaps();
 
 
+	static void clear_thread_load_tasks();
+
 	static void set_load_callback(ResourceLoadedCallback p_callback);
 	static void set_load_callback(ResourceLoadedCallback p_callback);
 	static ResourceLoaderImport import;
 	static ResourceLoaderImport import;
 
 

+ 2 - 0
main/main.cpp

@@ -3328,6 +3328,8 @@ void Main::cleanup(bool p_force) {
 	ResourceLoader::clear_translation_remaps();
 	ResourceLoader::clear_translation_remaps();
 	ResourceLoader::clear_path_remaps();
 	ResourceLoader::clear_path_remaps();
 
 
+	ResourceLoader::clear_thread_load_tasks();
+
 	ScriptServer::finish_languages();
 	ScriptServer::finish_languages();
 
 
 	// Sync pending commands that may have been queued from a different thread during ScriptServer finalization
 	// Sync pending commands that may have been queued from a different thread during ScriptServer finalization