Fix #133189: crash when hiding inline socket

Now the output socket checks if the corresponding inline socket that it should
be aligned with is visible.

This is an alternative to #133271 which had the problem that it resulted in
`flat_item::Socket` instances for which the input and output is `nullptr`.

Pull Request: https://projects.blender.org/blender/blender/pulls/133325
This commit is contained in:
Jacques Lucke
2025-01-20 22:53:10 +01:00
parent 350bd60b11
commit 46ece39c1a

View File

@@ -695,13 +695,19 @@ static void determine_visible_panels(const bNode &node, MutableSpan<bool> r_visi
static void add_flat_items_for_socket(bNode &node,
const nodes::SocketDeclaration &socket_decl,
const nodes::PanelDeclaration *panel_decl,
const nodes::SocketDeclaration *prev_socket_decl,
Vector<FlatNodeItem> &r_items)
{
bNodeSocket &socket = node.socket_by_decl(socket_decl);
if (!socket.is_visible()) {
return;
}
if (!socket_decl.align_with_previous_socket) {
if (socket_decl.align_with_previous_socket) {
if (!prev_socket_decl || !node.socket_by_decl(*prev_socket_decl).is_visible()) {
r_items.append({flat_item::Socket()});
}
}
else {
r_items.append({flat_item::Socket()});
}
flat_item::Socket &item = std::get<flat_item::Socket>(r_items.last().item);
@@ -745,19 +751,24 @@ static void add_flat_items_for_panel(bNode &node,
return;
}
r_items.append({flat_item::PanelContentBegin{&panel_decl}});
const nodes::SocketDeclaration *prev_socket_decl = nullptr;
for (const nodes::ItemDeclaration *item_decl : panel_decl.items) {
if (const auto *socket_decl = dynamic_cast<const nodes::SocketDeclaration *>(item_decl)) {
add_flat_items_for_socket(node, *socket_decl, &panel_decl, r_items);
add_flat_items_for_socket(node, *socket_decl, &panel_decl, prev_socket_decl, r_items);
prev_socket_decl = socket_decl;
}
else if (const auto *sub_panel_decl = dynamic_cast<const nodes::PanelDeclaration *>(item_decl))
{
add_flat_items_for_panel(node, *sub_panel_decl, panel_visibility, r_items);
}
else if (dynamic_cast<const nodes::SeparatorDeclaration *>(item_decl)) {
add_flat_items_for_separator(r_items);
}
else if (const auto *layout_decl = dynamic_cast<const nodes::LayoutDeclaration *>(item_decl)) {
add_flat_items_for_layout(node, *layout_decl, r_items);
else {
if (const auto *sub_panel_decl = dynamic_cast<const nodes::PanelDeclaration *>(item_decl)) {
add_flat_items_for_panel(node, *sub_panel_decl, panel_visibility, r_items);
}
else if (dynamic_cast<const nodes::SeparatorDeclaration *>(item_decl)) {
add_flat_items_for_separator(r_items);
}
else if (const auto *layout_decl = dynamic_cast<const nodes::LayoutDeclaration *>(item_decl))
{
add_flat_items_for_layout(node, *layout_decl, r_items);
}
prev_socket_decl = nullptr;
}
}
r_items.append({flat_item::PanelContentEnd{&panel_decl}});
@@ -775,19 +786,26 @@ static Vector<FlatNodeItem> make_flat_node_items(bNode &node)
Array<bool> panel_visibility(panels_num, false);
determine_visible_panels(node, panel_visibility);
const nodes::SocketDeclaration *prev_socket_decl = nullptr;
Vector<FlatNodeItem> items;
for (const nodes::ItemDeclaration *item_decl : node.declaration()->root_items) {
if (const auto *socket_decl = dynamic_cast<const nodes::SocketDeclaration *>(item_decl)) {
add_flat_items_for_socket(node, *socket_decl, nullptr, items);
add_flat_items_for_socket(node, *socket_decl, nullptr, prev_socket_decl, items);
prev_socket_decl = socket_decl;
}
else if (const auto *panel_decl = dynamic_cast<const nodes::PanelDeclaration *>(item_decl)) {
add_flat_items_for_panel(node, *panel_decl, panel_visibility, items);
}
else if (dynamic_cast<const nodes::SeparatorDeclaration *>(item_decl)) {
add_flat_items_for_separator(items);
}
else if (const auto *layout_decl = dynamic_cast<const nodes::LayoutDeclaration *>(item_decl)) {
add_flat_items_for_layout(node, *layout_decl, items);
else {
if (const auto *panel_decl = dynamic_cast<const nodes::PanelDeclaration *>(item_decl)) {
add_flat_items_for_panel(node, *panel_decl, panel_visibility, items);
}
else if (dynamic_cast<const nodes::SeparatorDeclaration *>(item_decl)) {
add_flat_items_for_separator(items);
}
else if (const auto *layout_decl = dynamic_cast<const nodes::LayoutDeclaration *>(item_decl))
{
add_flat_items_for_layout(node, *layout_decl, items);
}
prev_socket_decl = nullptr;
}
}
return items;