-
Notifications
You must be signed in to change notification settings - Fork 258
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
[BUG] Invalid selected nodes #59
Comments
Oh drat, that is a wrinkle I haven't thought about 🤔 If you have some working code which fixes this, feel free to submit a pr! |
A better solution would be to track selected nodes using their id instead of index and removing the id from the list at the EndNodeEditor() if the node was not drawn. |
Related to this, but not exactly the same issue (although likely related to the second comment by @brukted), is that when I delete a node, then create a new node and select it, the selected node index refers to the index of the node I just deleted. Here is an example: I create two nodes with index 1, 3. Then I delete them. Then I create two more nodes and select them. |
Yes, GetSelectedNodes is returning ids from nodes already deleted. IsNodeHovered also reports wrong ids: when a node is deleted and a new one created the old one id is reported.
@brukted |
@sonoro1234 |
@brukted I have tried calling ClearNodeSelection() after GetSelectedNodes and deletion without success: calling GetSelectedNodes when there is a new selection gives me ids that were already deleted. @Nelarius |
Hi, guys i fix this. The bug appeared if the new node was created using memory of the node from free_nodes, in this case the node id was not updated |
Ok, finally spent some time trying to get to the bottom of this. Thanks for the patience! 🙏 Like some of you already noticed, and submitted fixes for, there was an oversight in the way nodes were getting recycled from the free list. I took @sonoro1234 's fix since it was the simplest (and that was actually the way the id was written to memory before I got all fancy in the object pool...) Massive thanks! The following frame after a node gets deleted, the function |
@sonoro1234 Some extra context, since you were curious about the usage of indices instead of ids. You're right that both the ids and indices are unique and seem redundant. But I wanted the user to be able to identify nodes (and other elements) with non-contiguous integers, since that seemed the least restrictive. Internally though, I wanted to store everything in a contiguous container for the sake of simplicity. Node/link/pin indices are used all over the place instead of direct pointers/references for memory safety reasons, since a container's backing memory might change location. Node indices are often cached internally to minimize the number of id->index lookups. Maybe it could work differently. The code has grown quite a bit more complicated in the two years since I started working on it, and particularly in the last couple of months, I've managed to break a number of things while making other changes, causing all kinds of regressions 😅 So, going forward, I think I really need to figure out a better way to test the full functionality of the UI when making changes. |
I prefer @WookeyBiscotti 's fix because it handles everything related to |
@nspotrepka @brukted Good point, I suppose it would be nice to able to programmatically clear the selection as well! 👍 |
@Nelarius It's worth mentioning that there is an almost identical function |
Yep, it does 😄 |
- Reused elements weren't getting initialized in a matching way as new elements - This could have lead to bugs where reused node state is retained from old nodes (i.e. a reused node is locked in place as draggable is still false from a previous element) - pin indices were only used in draw_node(), so it is fine to reset them in the node update pass.
Recently I tried a node editor that is able to delete selected nodes. The problem is that imnodes uses the node index to keep track of selected nodes which causes from assertion fails to invalid nodes being reported as selected. The solution I took was to clear the selection every time I deleted a selected node. I can make a pr if you like the solution.
The text was updated successfully, but these errors were encountered: