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

NullReferenceException in SelectNode when mouseDown is followed by mouseUp too quickly because hoveredNode is null #367

Open
YoriKv opened this issue Apr 21, 2023 · 1 comment

Comments

@YoriKv
Copy link

YoriKv commented Apr 21, 2023

When mouseDown is followed by mouseUp too quickly, exactly one frame apart, SelectNode causes a null reference exception.

                        // If click node header, select it.
                        if (currentActivity == NodeActivity.HoldNode && !(e.control || e.shift)) {
                            selectedReroutes.Clear();
                            SelectNode(hoveredNode, false);

This appears to be because of the following line of code:

Vector2 nodeSize = GUILayoutUtility.GetLastRect().size;

On the frame that mouseDown is called, we get a frame that is the mouse event frame and on this line of code GUILayoutUtility.GetLastRect().size; returns (1, 1) for the size causing hoveredNode to be set to null and cause the exception on the next frame.

I'm not sure if this is the correct solution, but locally my solution was to change that line to this instead:
Vector2 nodeSize = nodeSizes[node];

@YoriKv
Copy link
Author

YoriKv commented Apr 21, 2023

After a bit further testing, my above solution seems to fix the issue in 99% of cases but it still occasionally happens immediately after the window is re-created the first time you click on a node and therefore before the nodeSize is cached. Still a significant improvement, but not a complete fix. I'm not entirely sure why nodeSize isn't cached on previous repaints, but that seems to be what's happening.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant