[Bf-blender-cvs] [6b33dafb64f] master: Geometry Nodes: add mutex for node ui storage

Jacques Lucke noreply at git.blender.org
Thu May 13 13:06:59 CEST 2021


Commit: 6b33dafb64f2e846eb4c7518a18f5cc011aed199
Author: Jacques Lucke
Date:   Thu May 13 13:06:09 2021 +0200
Branches: master
https://developer.blender.org/rB6b33dafb64f2e846eb4c7518a18f5cc011aed199

Geometry Nodes: add mutex for node ui storage

Previously, multiple threads adding information to node ui storage
at the same time resulted in memory corruption. The lock prevents
that, but might potentially become a bottleneck in the future.
For now favour correctness over a potential performance bottleneck.

===================================================================

M	source/blender/blenkernel/BKE_node_ui_storage.hh
M	source/blender/blenkernel/intern/node_ui_storage.cc

===================================================================

diff --git a/source/blender/blenkernel/BKE_node_ui_storage.hh b/source/blender/blenkernel/BKE_node_ui_storage.hh
index 5f9c039ef9e..8bf89cd8f58 100644
--- a/source/blender/blenkernel/BKE_node_ui_storage.hh
+++ b/source/blender/blenkernel/BKE_node_ui_storage.hh
@@ -95,8 +95,16 @@ struct AvailableAttributeInfo {
 };
 
 struct NodeUIStorage {
+  std::mutex mutex;
   blender::Vector<NodeWarning> warnings;
   blender::Set<AvailableAttributeInfo> attribute_hints;
+
+  NodeUIStorage() = default;
+  /* Needed because the mutex can't be moved or copied. */
+  NodeUIStorage(NodeUIStorage &&other)
+      : warnings(std::move(other.warnings)), attribute_hints(std::move(other.attribute_hints))
+  {
+  }
 };
 
 struct NodeTreeUIStorage {
diff --git a/source/blender/blenkernel/intern/node_ui_storage.cc b/source/blender/blenkernel/intern/node_ui_storage.cc
index cc910bab6ac..7a28fd295fb 100644
--- a/source/blender/blenkernel/intern/node_ui_storage.cc
+++ b/source/blender/blenkernel/intern/node_ui_storage.cc
@@ -152,6 +152,7 @@ void BKE_nodetree_error_message_add(bNodeTree &ntree,
   node_error_message_log(ntree, node, message, type);
 
   NodeUIStorage &node_ui_storage = node_ui_storage_ensure(ntree, context, node);
+  std::lock_guard lock{node_ui_storage.mutex};
   node_ui_storage.warnings.append({type, std::move(message)});
 }
 
@@ -163,6 +164,7 @@ void BKE_nodetree_attribute_hint_add(bNodeTree &ntree,
                                      const CustomDataType data_type)
 {
   NodeUIStorage &node_ui_storage = node_ui_storage_ensure(ntree, context, node);
+  std::lock_guard lock{node_ui_storage.mutex};
   node_ui_storage.attribute_hints.add_as(
       AvailableAttributeInfo{attribute_name, domain, data_type});
 }



More information about the Bf-blender-cvs mailing list