Fix: crash when adding repeat zone from search

The issue was that some code expected the "extend" sockets
to always exist. This was already always true from the user
point of view, but not internally.

There are different possible fixes, but this patch makes sure
that the extend socket will be available as expected. This is
achieved by making them part of the static node declaration.
We want to extend the static declaration of such dynamic
nodes anyway, to improve reflection capabilities without
having to instantiate nodes.
This commit is contained in:
Jacques Lucke
2024-01-17 12:45:06 +01:00
parent e39bd974a0
commit f811e9c6d6
2 changed files with 31 additions and 35 deletions
@@ -26,27 +26,24 @@ static void node_declare(NodeDeclarationBuilder &b)
const bNode *node = b.node_or_null();
const bNodeTree *tree = b.tree_or_null();
if (ELEM(nullptr, node, tree)) {
return;
}
const NodeGeometryRepeatInput &storage = node_storage(*node);
const bNode *output_node = tree->node_by_id(storage.output_node_id);
if (output_node == nullptr) {
return;
}
const auto &output_storage = *static_cast<const NodeGeometryRepeatOutput *>(
output_node->storage);
for (const int i : IndexRange(output_storage.items_num)) {
const NodeRepeatItem &item = output_storage.items[i];
const eNodeSocketDatatype socket_type = eNodeSocketDatatype(item.socket_type);
const StringRef name = item.name ? item.name : "";
const std::string identifier = RepeatItemsAccessor::socket_identifier_for_item(item);
auto &input_decl = b.add_input(socket_type, name, identifier);
auto &output_decl = b.add_output(socket_type, name, identifier);
if (socket_type_supports_fields(socket_type)) {
input_decl.supports_field();
output_decl.dependent_field({input_decl.input_index()});
if (node && tree) {
const NodeGeometryRepeatInput &storage = node_storage(*node);
const bNode *output_node = tree->node_by_id(storage.output_node_id);
if (output_node) {
const auto &output_storage = *static_cast<const NodeGeometryRepeatOutput *>(
output_node->storage);
for (const int i : IndexRange(output_storage.items_num)) {
const NodeRepeatItem &item = output_storage.items[i];
const eNodeSocketDatatype socket_type = eNodeSocketDatatype(item.socket_type);
const StringRef name = item.name ? item.name : "";
const std::string identifier = RepeatItemsAccessor::socket_identifier_for_item(item);
auto &input_decl = b.add_input(socket_type, name, identifier);
auto &output_decl = b.add_output(socket_type, name, identifier);
if (socket_type_supports_fields(socket_type)) {
input_decl.supports_field();
output_decl.dependent_field({input_decl.input_index()});
}
}
}
}
b.add_input<decl::Extend>("", "__extend__");
@@ -27,20 +27,19 @@ NODE_STORAGE_FUNCS(NodeGeometryRepeatOutput);
static void node_declare(NodeDeclarationBuilder &b)
{
const bNode *node = b.node_or_null();
if (node == nullptr) {
return;
}
const NodeGeometryRepeatOutput &storage = node_storage(*node);
for (const int i : IndexRange(storage.items_num)) {
const NodeRepeatItem &item = storage.items[i];
const eNodeSocketDatatype socket_type = eNodeSocketDatatype(item.socket_type);
const StringRef name = item.name ? item.name : "";
const std::string identifier = RepeatItemsAccessor::socket_identifier_for_item(item);
auto &input_decl = b.add_input(socket_type, name, identifier);
auto &output_decl = b.add_output(socket_type, name, identifier);
if (socket_type_supports_fields(socket_type)) {
input_decl.supports_field();
output_decl.dependent_field({input_decl.input_index()});
if (node) {
const NodeGeometryRepeatOutput &storage = node_storage(*node);
for (const int i : IndexRange(storage.items_num)) {
const NodeRepeatItem &item = storage.items[i];
const eNodeSocketDatatype socket_type = eNodeSocketDatatype(item.socket_type);
const StringRef name = item.name ? item.name : "";
const std::string identifier = RepeatItemsAccessor::socket_identifier_for_item(item);
auto &input_decl = b.add_input(socket_type, name, identifier);
auto &output_decl = b.add_output(socket_type, name, identifier);
if (socket_type_supports_fields(socket_type)) {
input_decl.supports_field();
output_decl.dependent_field({input_decl.input_index()});
}
}
}
b.add_input<decl::Extend>("", "__extend__");