GLTF: Mutex guard all_document_extensions

This commit is contained in:
nikitalita
2026-06-19 14:39:53 -07:00
parent 0dd6299f71
commit 91f1f9197c
3 changed files with 14 additions and 7 deletions
@@ -195,8 +195,9 @@ void EditorSceneExporterGLTFSettings::generate_property_list(Ref<GLTFDocument> p
_property_list.clear();
_document = p_document;
String image_format_hint_string = "None,PNG,JPEG";
const Vector<Ref<GLTFDocumentExtension>> all_extensions = GLTFDocument::get_all_gltf_document_extensions();
// If an extension allows saving images in different formats, add to the enum.
for (Ref<GLTFDocumentExtension> &extension : GLTFDocument::get_all_gltf_document_extensions()) {
for (const Ref<GLTFDocumentExtension> &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<GLTFDocument> 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<GLTFDocumentExtension> &extension : GLTFDocument::get_all_gltf_document_extensions()) {
for (const Ref<GLTFDocumentExtension> &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)) {
+10 -5
View File
@@ -5312,7 +5312,7 @@ Ref<GLTFObjectModelProperty> GLTFDocument::import_object_model_property(Ref<GLTF
// It should check `split.size() > 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<GLTFDocumentExtension> ext : all_document_extensions) {
for (Ref<GLTFDocumentExtension> 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<GLTFObjectModelProperty> GLTFDocument::export_object_model_property(Ref<GLTF
ret->set_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<GLTFDocumentExtension> ext : all_document_extensions) {
for (Ref<GLTFDocumentExtension> 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<GLTFState> p_state, const String &p_path, Ref<Fil
ERR_FAIL_COND_V(err != OK, err);
document_extensions.clear();
for (Ref<GLTFDocumentExtension> ext : all_document_extensions) {
for (Ref<GLTFDocumentExtension> ext : get_all_gltf_document_extensions()) {
ERR_CONTINUE(ext.is_null());
Ref<GLTFDocumentExtension> ext_dup = ext;
if (ClassDB::is_class_exposed(ext->get_class_name())) {
@@ -6930,8 +6930,10 @@ void GLTFDocument::_build_parent_hierarchy(Ref<GLTFState> p_state) {
}
Vector<Ref<GLTFDocumentExtension>> GLTFDocument::all_document_extensions;
Mutex GLTFDocument::all_document_extensions_mutex;
void GLTFDocument::register_gltf_document_extension(Ref<GLTFDocumentExtension> 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<GLTFDocumentExtension> p
}
void GLTFDocument::unregister_gltf_document_extension(Ref<GLTFDocumentExtension> 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<Ref<GLTFDocumentExtension>> GLTFDocument::get_all_gltf_document_extensions() {
MutexLock lock(all_document_extensions_mutex);
return all_document_extensions;
}
@@ -6975,7 +6980,7 @@ HashSet<String> 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<GLTFDocumentExtension> ext : all_document_extensions) {
for (Ref<GLTFDocumentExtension> ext : get_all_gltf_document_extensions()) {
ERR_CONTINUE(ext.is_null());
Vector<String> 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<GLTFState> 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<GLTFDocumentExtension> ext : all_document_extensions) {
for (Ref<GLTFDocumentExtension> ext : get_all_gltf_document_extensions()) {
ERR_CONTINUE(ext.is_null());
Ref<GLTFDocumentExtension> ext_dup = ext;
if (ClassDB::is_class_exposed(ext->get_class_name())) {
+1
View File
@@ -87,6 +87,7 @@ protected:
static void _bind_methods();
String _gen_unique_name(Ref<GLTFState> p_state, const String &p_name);
static Vector<Ref<GLTFDocumentExtension>> all_document_extensions;
static Mutex all_document_extensions_mutex;
Vector<Ref<GLTFDocumentExtension>> document_extensions;
public: