Repository navigation
Stop TargetDef::getMatchingTargets at an inheritance cycle - #3121
Open
shubhamrai9122-creator wants to merge 1 commit into
Open
shubhamrai9122-creator wants to merge 1 commit into
shubhamrai9122-creator wants to merge 1 commit into
Conversation
A targetdef that inherits from itself, or a cycle of targetdefs, made getMatchingTargets() loop forever while its result grew without bound, which hung NodeDef::getImplementation() for that target. Each target is now returned once and the walk stops at the first repeat. Signed-off-by: shubhamrai9122-creator <shubhamrai9122@gmail.com>
This branch has not been deployed
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.
Description
Fixes #3096
TargetDef::getMatchingTargets()followedinheritwithwhile (base). A targetdef that inherits from itself, or two that inherit from each other, never reached a null base, so the loop never ended and the result vector kept growing.NodeDef::getImplementation()calls it for any non-empty target, so it hung there too.Changes
getMatchingTargets()keeps aStringSetof the targets it has returned and stops at the first repeat. A self-inheritingTgives{ "T" }, a cycleT1→T2→T1gives{ "T1", "T2" }, and a normal chain is unchanged.traverseInheritance(), which throwsExceptionFoundCycle. That waygetImplementation()returnsnullptrfor these documents instead of throwing from code paths that don't expect it, which is also what the regression test in the issue expects.validate()already reports the cycle (Cycle in element inheritance chain).Testing
Added
TargetDef inheritance cycleinMaterialXTest/MaterialXCore/Node.cpp, using the self- and mutual-cycle cases from the issue plus a normal two-level chain. Without the fix the test hangs (I ran it under a 20 s alarm and it was killed); with it, it passes. All Core test groups pass: 767 assertions in 38 test cases, run from the repository root.