Skip to content

Commit fe49429

Browse files
committed
Merge branch 'gltf-mutex-all-document-extensions'
2 parents a4462f9 + 91f1f91 commit fe49429

3 files changed

Lines changed: 14 additions & 7 deletions

File tree

modules/gltf/editor/editor_scene_exporter_gltf_settings.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,9 @@ void EditorSceneExporterGLTFSettings::generate_property_list(Ref<GLTFDocument> p
195195
_property_list.clear();
196196
_document = p_document;
197197
String image_format_hint_string = "None,PNG,JPEG";
198+
const Vector<Ref<GLTFDocumentExtension>> all_extensions = GLTFDocument::get_all_gltf_document_extensions();
198199
// If an extension allows saving images in different formats, add to the enum.
199-
for (Ref<GLTFDocumentExtension> &extension : GLTFDocument::get_all_gltf_document_extensions()) {
200+
for (const Ref<GLTFDocumentExtension> &extension : all_extensions) {
200201
PackedStringArray saveable_image_formats = extension->get_saveable_image_formats();
201202
for (int i = 0; i < saveable_image_formats.size(); i++) {
202203
image_format_hint_string += "," + saveable_image_formats[i];
@@ -219,7 +220,7 @@ void EditorSceneExporterGLTFSettings::generate_property_list(Ref<GLTFDocument> p
219220
_property_list.push_back(visibility_mode_prop);
220221
}
221222
// Now that the above code set up base glTF stuff, add properties from all document extensions.
222-
for (Ref<GLTFDocumentExtension> &extension : GLTFDocument::get_all_gltf_document_extensions()) {
223+
for (const Ref<GLTFDocumentExtension> &extension : all_extensions) {
223224
// Set up to listen for property changes.
224225
const Callable on_prop_changed = callable_mp(this, &EditorSceneExporterGLTFSettings::_on_extension_property_list_changed);
225226
if (!extension->is_connected(CoreStringName(property_list_changed), on_prop_changed)) {

modules/gltf/gltf_document.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5321,7 +5321,7 @@ Ref<GLTFObjectModelProperty> GLTFDocument::import_object_model_property(Ref<GLTF
53215321
// It should check `split.size() > 4 and split[0] == "nodes" and split[2] == "extensions" and split[3] == "MY_ext"`
53225322
// at the start of the function to check if this JSON pointer applies to it, then it can handle `split[4]`.
53235323
if (!ret->has_node_paths()) {
5324-
for (Ref<GLTFDocumentExtension> ext : all_document_extensions) {
5324+
for (Ref<GLTFDocumentExtension> ext : get_all_gltf_document_extensions()) {
53255325
ret = ext->import_object_model_property(p_state, split, partial_paths);
53265326
if (ret.is_valid() && ret->has_node_paths()) {
53275327
if (!ret->has_json_pointers()) {
@@ -5571,7 +5571,7 @@ Ref<GLTFObjectModelProperty> GLTFDocument::export_object_model_property(Ref<GLTF
55715571
ret->set_json_pointers(split_json_pointers);
55725572
} else {
55735573
// We don't have a mapping, so we need to ask GLTFDocumentExtension classes if they have a mapping.
5574-
for (Ref<GLTFDocumentExtension> ext : all_document_extensions) {
5574+
for (Ref<GLTFDocumentExtension> ext : get_all_gltf_document_extensions()) {
55755575
ret = ext->export_object_model_property(p_state, p_node_path, p_godot_node, p_gltf_node_index, target_object, target_prop_depth);
55765576
if (ret.is_valid() && ret->has_json_pointers()) {
55775577
if (!ret->has_node_paths()) {
@@ -6731,7 +6731,7 @@ Error GLTFDocument::_parse(Ref<GLTFState> p_state, const String &p_path, Ref<Fil
67316731
ERR_FAIL_COND_V(err != OK, err);
67326732

67336733
document_extensions.clear();
6734-
for (Ref<GLTFDocumentExtension> ext : all_document_extensions) {
6734+
for (Ref<GLTFDocumentExtension> ext : get_all_gltf_document_extensions()) {
67356735
ERR_CONTINUE(ext.is_null());
67366736
Ref<GLTFDocumentExtension> ext_dup = ext;
67376737
if (ClassDB::is_class_exposed(ext->get_class_name())) {
@@ -6962,8 +6962,10 @@ void GLTFDocument::_build_parent_hierarchy(Ref<GLTFState> p_state) {
69626962
}
69636963

69646964
Vector<Ref<GLTFDocumentExtension>> GLTFDocument::all_document_extensions;
6965+
Mutex GLTFDocument::all_document_extensions_mutex;
69656966

69666967
void GLTFDocument::register_gltf_document_extension(Ref<GLTFDocumentExtension> p_extension, bool p_first_priority) {
6968+
MutexLock lock(all_document_extensions_mutex);
69676969
if (!all_document_extensions.has(p_extension)) {
69686970
if (p_first_priority) {
69696971
all_document_extensions.insert(0, p_extension);
@@ -6974,14 +6976,17 @@ void GLTFDocument::register_gltf_document_extension(Ref<GLTFDocumentExtension> p
69746976
}
69756977

69766978
void GLTFDocument::unregister_gltf_document_extension(Ref<GLTFDocumentExtension> p_extension) {
6979+
MutexLock lock(all_document_extensions_mutex);
69776980
all_document_extensions.erase(p_extension);
69786981
}
69796982

69806983
void GLTFDocument::unregister_all_gltf_document_extensions() {
6984+
MutexLock lock(all_document_extensions_mutex);
69816985
all_document_extensions.clear();
69826986
}
69836987

69846988
Vector<Ref<GLTFDocumentExtension>> GLTFDocument::get_all_gltf_document_extensions() {
6989+
MutexLock lock(all_document_extensions_mutex);
69856990
return all_document_extensions;
69866991
}
69876992

@@ -7007,7 +7012,7 @@ HashSet<String> GLTFDocument::get_supported_gltf_extensions_hashset() {
70077012
supported_extensions.insert("KHR_materials_unlit");
70087013
supported_extensions.insert("KHR_node_visibility");
70097014
supported_extensions.insert("KHR_texture_transform");
7010-
for (Ref<GLTFDocumentExtension> ext : all_document_extensions) {
7015+
for (Ref<GLTFDocumentExtension> ext : get_all_gltf_document_extensions()) {
70117016
ERR_CONTINUE(ext.is_null());
70127017
Vector<String> ext_supported_extensions = ext->get_supported_extensions();
70137018
for (int i = 0; i < ext_supported_extensions.size(); ++i) {
@@ -7307,7 +7312,7 @@ Error GLTFDocument::append_from_scene(Node *p_node, Ref<GLTFState> p_state, uint
73077312
// Perform export preflight for document extensions. Only extensions that
73087313
// return OK will be used for the rest of the export steps.
73097314
document_extensions.clear();
7310-
for (Ref<GLTFDocumentExtension> ext : all_document_extensions) {
7315+
for (Ref<GLTFDocumentExtension> ext : get_all_gltf_document_extensions()) {
73117316
ERR_CONTINUE(ext.is_null());
73127317
Ref<GLTFDocumentExtension> ext_dup = ext;
73137318
if (ClassDB::is_class_exposed(ext->get_class_name())) {

modules/gltf/gltf_document.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class GLTFDocument : public Resource {
8787
static void _bind_methods();
8888
String _gen_unique_name(Ref<GLTFState> p_state, const String &p_name);
8989
static Vector<Ref<GLTFDocumentExtension>> all_document_extensions;
90+
static Mutex all_document_extensions_mutex;
9091
Vector<Ref<GLTFDocumentExtension>> document_extensions;
9192

9293
public:

0 commit comments

Comments
 (0)