diff options
author | Jacques Lucke <jacques@blender.org> | 2021-05-13 14:06:09 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2021-05-13 14:06:09 +0300 |
commit | 6b33dafb64f2e846eb4c7518a18f5cc011aed199 (patch) | |
tree | c3a5c177ab7e2ae51a35c82bb993d3f61fe8e127 /source/blender | |
parent | 250a5442cf53a7fc435ecc293517e24ef6bcb46f (diff) |
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.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/BKE_node_ui_storage.hh | 8 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/node_ui_storage.cc | 2 |
2 files changed, 10 insertions, 0 deletions
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}); } |