Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2021-05-13 14:06:09 +0300
committerJacques Lucke <jacques@blender.org>2021-05-13 14:06:09 +0300
commit6b33dafb64f2e846eb4c7518a18f5cc011aed199 (patch)
treec3a5c177ab7e2ae51a35c82bb993d3f61fe8e127 /source/blender
parent250a5442cf53a7fc435ecc293517e24ef6bcb46f (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.hh8
-rw-r--r--source/blender/blenkernel/intern/node_ui_storage.cc2
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});
}