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

Infinite loop on Sort Nodes #17

Open
cristiangj opened this issue Jul 19, 2021 · 1 comment
Open

Infinite loop on Sort Nodes #17

cristiangj opened this issue Jul 19, 2021 · 1 comment

Comments

@cristiangj
Copy link

If you make a cyclical graph (a parent having a reference to a children and this children to their parent) you have a infinite loop on UEdGraph_GenericGraph::SortNodes after call UEdGraph_GenericGraph::RebuildGenericGraph.
The issue is that CurrLevelNodes never is empty because the parent finds the children and the children to the parent

@cristiangj
Copy link
Author

cristiangj commented Jul 20, 2021

Quick fix to be able to work with cyclical references (adding AlreadyVisitedNodes registry to avoid Children access to their parents):

`

void UEdGraph_GenericGraph::SortNodes(UGenericGraphNode* RootNode)
{

int Level = 0;
TArray<UGenericGraphNode*> CurrLevelNodes = { RootNode };
TArray<UGenericGraphNode*> NextLevelNodes;
TArray<UGenericGraphNode*> AlreadyVisitedNodes;

while (CurrLevelNodes.Num() != 0)
{
	int32 LevelWidth = 0;
	for (int i = 0; i < CurrLevelNodes.Num(); ++i)
	{
		UGenericGraphNode* Node = CurrLevelNodes[i];

		auto Comp = [&](const UGenericGraphNode& L, const UGenericGraphNode& R)
		{
			UEdNode_GenericGraphNode* EdNode_LNode = NodeMap[&L];
			UEdNode_GenericGraphNode* EdNode_RNode = NodeMap[&R];
			return EdNode_LNode->NodePosX < EdNode_RNode->NodePosX;
		};

		Node->ChildrenNodes.Sort(Comp);
		Node->ParentNodes.Sort(Comp);

		for (int j = 0; j < Node->ChildrenNodes.Num(); ++j)
		{
			if (!AlreadyVisitedNodes.Contains(Node->ChildrenNodes[j]))
			{
				NextLevelNodes.Add(Node->ChildrenNodes[j]);
				AlreadyVisitedNodes.Add(Node->ChildrenNodes[j]);
			}
		}
	}

	CurrLevelNodes = NextLevelNodes;
	NextLevelNodes.Reset();
	++Level;
}

}`

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