Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After deleting and re-creating nodes, attribute pins can become non-interactable. #91

Open
francesco-cattoglio opened this issue Mar 23, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@francesco-cattoglio
Copy link

francesco-cattoglio commented Mar 23, 2021

This is basically the counter-part of #71 but for pins instead of nodes.

First and foremost: this is the code to reproduce the bug

    void RenderTestFrame() {
        ImGui::Begin("simple node editor");

        imnodes::BeginNodeEditor();

        static int i = 0;
        if (i == 0) { // frame 1
            imnodes::BeginNode(3);
                imnodes::BeginOutputAttribute(3);
                    ImGui::Text("out_3");
                imnodes::EndOutputAttribute();
            imnodes::EndNode();
            imnodes::BeginNode(1);
                imnodes::BeginOutputAttribute(1);
                    ImGui::Text("out_1");
                imnodes::EndOutputAttribute();
                imnodes::BeginInputAttribute(2);
                    ImGui::Text("in_2");
                imnodes::EndInputAttribute();
            imnodes::EndNode();
                i++;
        } else if (i == 1) { // frame 2
                i++;
        } else if (i >= 2) { // frame 3 onwards
            imnodes::BeginNode(3);
                imnodes::BeginNodeTitleBar();
                    ImGui::TextUnformatted("try using attribute pin");
                imnodes::EndNodeTitleBar();
                imnodes::BeginOutputAttribute(3);
                    ImGui::Text("out_3");
                imnodes::EndOutputAttribute();
            imnodes::EndNode();
            i++;
        }

        imnodes::EndNodeEditor();
        ImGui::End();
    }

From the third call of RenderTestFrame() onwards, the pin on the node will not be interactive anymore, because the state of the PinData object pool is messed up.
I am currently using revision ee6d407 because I am stuck with an older version of imgui, but I am pretty sure you will be able to reproduce on master as well.

The culprit is the following block inside imnodes.cpp

template<typename T>
void object_pool_update(ObjectPool<T>& objects)
{
    objects.free_list.clear();
    for (int i = 0; i < objects.in_use.size(); ++i)
    {
        if (!objects.in_use[i])
        {
            objects.id_map.SetInt(objects.pool[i].id, -1);
            objects.free_list.push_back(i);
            (objects.pool.Data + i)->~T();
        }
    }
}

In this situation, a pin is not in use, and therefore the id_map at the related id gets reset to -1. However, since the destructor of a PinData does nothing, the value in memory stays there and that id will be reset over and over again, even if that id is currently used by another PinData in a different slot.
My fix for that was to add a destructor to the PinData that resets the stored ID to INT_MIN and add an a relevant check to the code. However I have not yet investigated if this is something that should be taken care of for links as well. In my experiments everything was fine without any change to the LinkData, but I had very little time to test that.

@Nelarius
Copy link
Owner

Thanks for bringing this up @francesco-cattoglio ! My goal is to fix all these issues at once when I refactor the internal object management: #81

@Nelarius Nelarius added the bug Something isn't working label Mar 28, 2021
@Nelarius Nelarius mentioned this issue May 31, 2022
18 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants