diff --git a/modules/gltf/editor/editor_scene_exporter_gltf_settings.cpp b/modules/gltf/editor/editor_scene_exporter_gltf_settings.cpp index b37e38f1f4..dc3c6709a5 100644 --- a/modules/gltf/editor/editor_scene_exporter_gltf_settings.cpp +++ b/modules/gltf/editor/editor_scene_exporter_gltf_settings.cpp @@ -195,8 +195,9 @@ void EditorSceneExporterGLTFSettings::generate_property_list(Ref p _property_list.clear(); _document = p_document; String image_format_hint_string = "None,PNG,JPEG"; + const Vector> all_extensions = GLTFDocument::get_all_gltf_document_extensions(); // If an extension allows saving images in different formats, add to the enum. - for (Ref &extension : GLTFDocument::get_all_gltf_document_extensions()) { + for (const Ref &extension : all_extensions) { PackedStringArray saveable_image_formats = extension->get_saveable_image_formats(); for (int i = 0; i < saveable_image_formats.size(); i++) { image_format_hint_string += "," + saveable_image_formats[i]; @@ -219,7 +220,7 @@ void EditorSceneExporterGLTFSettings::generate_property_list(Ref p _property_list.push_back(visibility_mode_prop); } // Now that the above code set up base glTF stuff, add properties from all document extensions. - for (Ref &extension : GLTFDocument::get_all_gltf_document_extensions()) { + for (const Ref &extension : all_extensions) { // Set up to listen for property changes. const Callable on_prop_changed = callable_mp(this, &EditorSceneExporterGLTFSettings::_on_extension_property_list_changed); if (!extension->is_connected(CoreStringName(property_list_changed), on_prop_changed)) { diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp index 4ffbcdec1c..d876fa4d19 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -5312,7 +5312,7 @@ Ref GLTFDocument::import_object_model_property(Ref 4 and split[0] == "nodes" and split[2] == "extensions" and split[3] == "MY_ext"` // at the start of the function to check if this JSON pointer applies to it, then it can handle `split[4]`. if (!ret->has_node_paths()) { - for (Ref ext : all_document_extensions) { + for (Ref ext : get_all_gltf_document_extensions()) { ret = ext->import_object_model_property(p_state, split, partial_paths); if (ret.is_valid() && ret->has_node_paths()) { if (!ret->has_json_pointers()) { @@ -5562,7 +5562,7 @@ Ref GLTFDocument::export_object_model_property(Refset_json_pointers(split_json_pointers); } else { // We don't have a mapping, so we need to ask GLTFDocumentExtension classes if they have a mapping. - for (Ref ext : all_document_extensions) { + for (Ref ext : get_all_gltf_document_extensions()) { ret = ext->export_object_model_property(p_state, p_node_path, p_godot_node, p_gltf_node_index, target_object, target_prop_depth); if (ret.is_valid() && ret->has_json_pointers()) { if (!ret->has_node_paths()) { @@ -6699,7 +6699,7 @@ Error GLTFDocument::_parse(Ref p_state, const String &p_path, Ref ext : all_document_extensions) { + for (Ref ext : get_all_gltf_document_extensions()) { ERR_CONTINUE(ext.is_null()); Ref ext_dup = ext; if (ClassDB::is_class_exposed(ext->get_class_name())) { @@ -6930,8 +6930,10 @@ void GLTFDocument::_build_parent_hierarchy(Ref p_state) { } Vector> GLTFDocument::all_document_extensions; +Mutex GLTFDocument::all_document_extensions_mutex; void GLTFDocument::register_gltf_document_extension(Ref p_extension, bool p_first_priority) { + MutexLock lock(all_document_extensions_mutex); if (!all_document_extensions.has(p_extension)) { if (p_first_priority) { all_document_extensions.insert(0, p_extension); @@ -6942,14 +6944,17 @@ void GLTFDocument::register_gltf_document_extension(Ref p } void GLTFDocument::unregister_gltf_document_extension(Ref p_extension) { + MutexLock lock(all_document_extensions_mutex); all_document_extensions.erase(p_extension); } void GLTFDocument::unregister_all_gltf_document_extensions() { + MutexLock lock(all_document_extensions_mutex); all_document_extensions.clear(); } Vector> GLTFDocument::get_all_gltf_document_extensions() { + MutexLock lock(all_document_extensions_mutex); return all_document_extensions; } @@ -6975,7 +6980,7 @@ HashSet GLTFDocument::get_supported_gltf_extensions_hashset() { supported_extensions.insert("KHR_materials_unlit"); supported_extensions.insert("KHR_node_visibility"); supported_extensions.insert("KHR_texture_transform"); - for (Ref ext : all_document_extensions) { + for (Ref ext : get_all_gltf_document_extensions()) { ERR_CONTINUE(ext.is_null()); Vector ext_supported_extensions = ext->get_supported_extensions(); for (int i = 0; i < ext_supported_extensions.size(); ++i) { @@ -7275,7 +7280,7 @@ Error GLTFDocument::append_from_scene(Node *p_node, Ref p_state, uint // Perform export preflight for document extensions. Only extensions that // return OK will be used for the rest of the export steps. document_extensions.clear(); - for (Ref ext : all_document_extensions) { + for (Ref ext : get_all_gltf_document_extensions()) { ERR_CONTINUE(ext.is_null()); Ref ext_dup = ext; if (ClassDB::is_class_exposed(ext->get_class_name())) { diff --git a/modules/gltf/gltf_document.h b/modules/gltf/gltf_document.h index a374a6d747..bf434cc6c6 100644 --- a/modules/gltf/gltf_document.h +++ b/modules/gltf/gltf_document.h @@ -87,6 +87,7 @@ protected: static void _bind_methods(); String _gen_unique_name(Ref p_state, const String &p_name); static Vector> all_document_extensions; + static Mutex all_document_extensions_mutex; Vector> document_extensions; public: