Fix infinite recursion in AutoLayout for empty graphs#25
Merged
Conversation
…archical algorithm AutoLayoutAlgorithm.ApplyCore's empty-graph (count == 0) fast path unconditionally delegated to the internal HierarchicalLayoutAlgorithm instance. That instance's own registry resolves both 'auto' and 'hierarchical' back to this same AutoLayoutAlgorithm instance (needed so nested 'auto' scopes re-evaluate correctly). Since an empty graph can never contain a container, HierarchicalLayoutAlgorithm.LayoutScope always takes its flat fast path and calls straight back into this same method with the same empty graph whenever the graph or options declare Algorithm as 'auto' or 'hierarchical' - infinite mutual recursion that overflows the stack (confirmed by reproduction: process exit code 0xC00000FD, STATUS_STACK_OVERFLOW). Fix: resolve the cascaded effective algorithm id directly in the empty-graph fast path, and short-circuit straight to the default leaf (layered) whenever it is self-referential, before ever consulting _hierarchical. Every other id still routes through _hierarchical.ApplyCore exactly as before, preserving existing resolution (and resolution-error) behavior unchanged. Added regression tests proving an empty graph with Algorithm explicitly set to 'auto' or 'hierarchical' resolves without crashing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request addresses a critical stack overflow issue that occurred when applying the
AutoLayoutAlgorithmto an empty graph with specific algorithm settings. The main changes ensure that self-referential algorithm resolution does not cause infinite recursion, and new tests are added to verify this behavior.Bug fix: Prevent infinite recursion on empty graphs
AutoLayoutAlgorithm.ApplyCoreto detect when the effective algorithm ID is self-referential (either"auto"or"hierarchical") for empty graphs, and to directly delegate to the layered algorithm instead of risking infinite recursion. This prevents a stack overflow when an empty graph explicitly sets its algorithm to"auto"or"hierarchical".Testing: Added regression tests for empty graph algorithm resolution
AutoLayoutAlgorithmTests.cs:Apply_EmptyGraph_ExplicitAutoAlgorithm_ReturnsEmptyTreeensures that an empty graph with algorithm"auto"returns an empty tree without recursion.Apply_EmptyGraph_ExplicitHierarchicalAlgorithm_ReturnsEmptyTreeensures that an empty graph with algorithm"hierarchical"also avoids recursion and returns an empty tree.