Nelarius / imnodes

A small, dependency-free node editor for dear imgui
MIT License
2.04k stars 249 forks source link

Crash during node or link delete operation #129

Open EssenOH opened 2 years ago

EssenOH commented 2 years ago

Crash happens if push consecutive 'x' key

Reproduction steps with links.

  1. create multiple nodes.
  2. connect the links between the nodes
  3. select a link
  4. push 'x' button to delete the link
  5. push 'x' button once again.. => crash

Reproduction steps with nodes.

  1. create multiple nodes.
  2. select a node
  3. push 'x' button to delete the node
  4. push 'x' button once again.. => crash

Visual confusion.

  1. create multiple nodes or links => the nodes or links already emphasized with bold color, but the node or link is not selected.
  2. push 'x' button => nothing happens because the selection index doesn't have any item.
1hAck-0 commented 2 years ago

It would be best if you show some code: how do you delete the nodes/links?

Green-Sky commented 2 years ago

I think @EssenWorkbench is referencing the example code.

This is not a library bug and likely a flaw in the example code.

nfwGytautas commented 2 years ago

I also encountered this problem, from what I investigated the problem is that ImNodes::NumSelectedNodes returns 1 when no node is selected and then after querying the node id it returns INT_MIN.

For me the code here is:

if (aderite::Engine::getInputManager()->isKeyPressed(input::Key::DEL)) {
    std::vector<int> nodes;
    LOG_TRACE("Num selected: {0}", ImNodes::NumSelectedNodes());
    nodes.resize(ImNodes::NumSelectedNodes());
    ImNodes::GetSelectedNodes(nodes.data());

    for (int node : nodes) {
        LOG_TRACE("Node: {0}", node);
        m_currentState->deleteNode(node);
    }
}

And the log:

[11:28:36.527] thread 18860 | Num selected: 1 [11:28:36.528] thread 18860 | Node: 26 [11:28:36.544] thread 18860 | Num selected: 1 [11:28:36.545] thread 18860 | Node: -2147483648 [11:28:36.546] thread 18860 | Failed to delete node -2147483648 [11:28:36.560] thread 18860 | Num selected: 1 [11:28:36.560] thread 18860 | Node: -2147483648 [11:28:36.561] thread 18860 | Failed to delete node -2147483648 [11:28:36.577] thread 18860 | Num selected: 1 [11:28:36.578] thread 18860 | Node: -2147483648 [11:28:36.578] thread 18860 | Failed to delete node -2147483648 [11:28:36.593] thread 18860 | Num selected: 1 [11:28:36.594] thread 18860 | Node: -2147483648 [11:28:36.595] thread 18860 | Failed to delete node -2147483648

This only happens when deleting a node. If I don't select anything and try to delete then num selected will return 0 as expected.

Green-Sky commented 2 years ago

... or it is? which version(commit) are you running? I am running a multiple months old commit with out issues (c63f347f06f16f78249bdd0914b1bc04dabc4f0a) .

nfwGytautas commented 2 years ago

I am using e563371cee49eb42da08cca1e0209d30d452c665

brukted commented 2 years ago

Please refer to here https://github.com/Nelarius/imnodes/blob/e563371cee49eb42da08cca1e0209d30d452c665/imnodes.h#L350-L364 Clearing the selected nodes or links before deletion is delegated to the user.

nfwGytautas commented 2 years ago

Yeah, that fixed it