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.
This commit is contained in:
parent
250a5442cf
commit
6b33dafb64
|
@ -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 {
|
||||
|
|
|
@ -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});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue