Skip to content

fix(graph): prevent crash when previewing node without outputs (#4883) - #4899

Open
HarshithJeevan-pixel wants to merge 3 commits into
GraphiteEditor:masterfrom
HarshithJeevan-pixel:fix-4883-preview-node-without-outputs
Open

HarshithJeevan-pixel wants to merge 3 commits into
GraphiteEditor:masterfrom
HarshithJeevan-pixel:fix-4883-preview-node-without-outputs

Conversation

@HarshithJeevan-pixel

Copy link
Copy Markdown

Fixes #4883

Description

When entering an empty custom node, returning to the document, and clicking "Preview", the editor panicked with:
panicked at node-graph/graph-craft/src/document.rs: index out of bounds: the len is 0 but the index is 0

This happened because:

  1. An empty custom node network has 0 exports, so its original_location.dependants has length 0.
  2. replace_node_with_its_exports and flatten_with_fns directly indexed into .dependants[...] without bounds checking.
  3. The graph bar and toggle_preview allowed setting preview on a node with 0 outputs.

Changes

  • Used .get() and .get_mut() for bounds-safe indexing into OriginalLocation.dependants.
  • Guarded toggle_preview and apply_previews against nodes with 0 outputs.
  • Hid the "Preview" button in the node graph bar when the selected node has no outputs.
  • Added regression tests for flattening nodes without exports and rejecting preview on 0-output nodes.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 5 files

Reply to a comment to ask cubic a question or push back. It learns from your replies.

Re-trigger cubic

Comment thread node-graph/graph-craft/src/document.rs Resolved
@TrueDoctor

Copy link
Copy Markdown
Member

The diff is definetly to big. We should do a targeted fix here and we should not require compiler changes

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

[Crash Report] When entering a custom node, going back, and clicking "Preview"

2 participants