Fix #121248: Crash executing node tool operator without active node

Calling `NODE_OT_select_same_type_step` when no node is active triggers
the crash.

Pull Request: https://projects.blender.org/blender/blender/pulls/121252
This commit is contained in:
Pratik Borhade
2024-05-01 14:48:12 +02:00
committed by Pratik Borhade
parent ff15d31bc1
commit 3c336c82cc

View File

@@ -1261,7 +1261,11 @@ static int node_select_same_type_step_exec(bContext *C, wmOperator *op)
SpaceNode *snode = CTX_wm_space_node(C);
ARegion *region = CTX_wm_region(C);
const bool prev = RNA_boolean_get(op->ptr, "prev");
bNode &active_node = *nodeGetActive(snode->edittree);
bNode *active_node = nodeGetActive(snode->edittree);
if (active_node == nullptr) {
return OPERATOR_CANCELLED;
}
bNodeTree &node_tree = *snode->edittree;
node_tree.ensure_topology_cache();
@@ -1270,7 +1274,7 @@ static int node_select_same_type_step_exec(bContext *C, wmOperator *op)
}
const Span<const bNode *> toposort = node_tree.toposort_left_to_right();
const int index = toposort.first_index(&active_node);
const int index = toposort.first_index(active_node);
int new_index = index;
while (true) {
@@ -1278,13 +1282,13 @@ static int node_select_same_type_step_exec(bContext *C, wmOperator *op)
if (!toposort.index_range().contains(new_index)) {
return OPERATOR_CANCELLED;
}
if (nodes_are_same_type_for_select(*toposort[new_index], active_node)) {
if (nodes_are_same_type_for_select(*toposort[new_index], *active_node)) {
break;
}
}
bNode *new_active_node = node_tree.all_nodes()[toposort[new_index]->index()];
if (new_active_node == &active_node) {
if (new_active_node == active_node) {
return OPERATOR_CANCELLED;
}