Fix T103964: Assert on mouse hover of empty node editor

The reverse iteration added in e091291b5b didn't handle
the case where there are no nodes properly. Thanks to Iliya Katueshenock
for investigating this.
This commit is contained in:
Hans Goudey 2023-01-19 15:49:49 -06:00
parent fe552bf236
commit 2ab72f6db8
Notes: blender-bot 2023-02-14 06:25:25 +01:00
Referenced by issue #103964, Node: Many assert in debug becous iterate on empty nodes from end
2 changed files with 7 additions and 2 deletions

View File

@ -2621,8 +2621,10 @@ int node_get_resize_cursor(NodeResizeDirection directions)
static const bNode *find_node_under_cursor(SpaceNode &snode, const float2 &cursor)
{
/* Check nodes front to back. */
const Span<bNode *> nodes = snode.edittree->all_nodes();
if (nodes.is_empty()) {
return nullptr;
}
for (int i = nodes.index_range().last(); i >= 0; i--) {
if (BLI_rctf_isect_pt(&nodes[i]->runtime->totr, cursor[0], cursor[1])) {
return nodes[i];

View File

@ -1135,8 +1135,11 @@ bNodeSocket *node_find_indicated_socket(SpaceNode &snode,
/* Sockets haven't been drawn yet, e.g. when the file is currently opening. */
return nullptr;
}
const Span<bNode *> nodes = snode.edittree->all_nodes();
if (nodes.is_empty()) {
return nullptr;
}
for (int i = nodes.index_range().last(); i >= 0; i--) {
bNode &node = *nodes[i];