thedmd / imgui-node-editor

Node Editor built using Dear ImGui
MIT License
3.48k stars 527 forks source link

Removing node does not delete connected links #276

Open sodamouse opened 5 months ago

sodamouse commented 5 months ago

Hi, I saw in another closed issue that this problem was fixed in develop, however this does not seem to be the case. When I delete a node, QueryDeletedLink does not return anything, and the second while loop is never executed.

Repro:

if (ax::NodeEditor::BeginDelete())
{
    ax::NodeEditor::NodeId deletedNodeId;
    while (ax::NodeEditor::QueryDeletedNode(&deletedNodeId))
    {
        if (ax::NodeEditor::AcceptDeletedItem)
        {
            auto it = std::find_if(nodes.begin(), nodes.end(), [deletedNodeId](Node& node) {
                return node.id == deletedNodeId.Get();
            });

            if (it != nodes.end())
            {
                std::cout << "removed node: " << it->id << '\n';
                nodes.erase(it);
            }
        }
    }

    ax::NodeEditor::LinkId deletedLinkId;
    while (ax::NodeEditor::QueryDeletedLink(&deletedLinkId))
    {
        if (ax::NodeEditor::AcceptDeletedItem())
        {
            auto it = std::find_if(links.begin(), links.end(), [deletedLinkId](Link& link) {
                return link.id == deletedLinkId.Get();
            });

            if (it != links.end())
            {
                std::cout << "removed link: " << it->id << '\n';
                links.erase(it);
            }
        }
    }

        ax::NodeEditor::EndDelete();
}