Right click in behavior tree editor crashed(AddClassGraphChildren crashing due to Careless written codes)

This bug is only reproducible when certain classes existed in UE4 project. It is impossible to reproduce by heavily testing for a simple project.

Please don’t try to use testing to reproduce this bug. Please let the programmer who wrote these codes take a look. Please take a look at the codes, and this bug drive us crazy when editing Behavior Tree. It crashes and crashes again when Right-Clicking in behavior tree editor. It makes behavior tree editor impossible to insert task nodes.

It is very easy to spot the bug by just looking codes. In the for loop NodeList’s elements number would decrease not only 1 due to recursively calling AddClassGraphChildren in the for loop that would also delete element of NodeList … So this would cause out of boundary error when execute NodeList[i]. It will also cause some tasks missed in the Right-Clicked Popup Menu.

 void FGraphNodeClassHelper::AddClassGraphChildren(TSharedPtr Node, TArray >& NodeList)
    {
    	if (!Node.IsValid())
    	{
    		return;
    	}
    
    	const FString NodeClassName = Node->Data.GetClassName();
    	for (int32 i = NodeList.Num() - 1; i >= 0; i--)
    	{
    		if (NodeList[i]->ParentClassName == NodeClassName)
    		{
    			TSharedPtr<FGraphNodeClassNode> MatchingNode = NodeList[i];
    			NodeList.RemoveAt(i);
    
    			MatchingNode->ParentNode = Node;
    			Node->SubNodes.Add(MatchingNode);
    
    			AddClassGraphChildren(MatchingNode, NodeList);
    		}
    	}
    }

Is anybody here???

???

Hello. No one here

Is anybody here??

???
???