Fix validation methods to avoid infinite loops.

This commit is contained in:
raiti-chan 2022-12-12 18:49:32 +09:00 committed by bd_
parent 5b97455c0f
commit 622ea7d387

View File

@ -205,9 +205,12 @@ namespace nadena.dev.modular_avatar.core.editor
return _avatarMenus == null || _avatarMenus.Contains(menu);
}
private static ValidateExpressionMenuIconResult ValidateExpressionMenuIcon(VRCExpressionsMenu menu)
private static ValidateExpressionMenuIconResult ValidateExpressionMenuIcon(VRCExpressionsMenu menu, HashSet<VRCExpressionsMenu> visitedMenus = null)
{
if (menu == null) return ValidateExpressionMenuIconResult.Success;
if (visitedMenus == null) visitedMenus = new HashSet<VRCExpressionsMenu>();
if (visitedMenus.Contains(menu)) return ValidateExpressionMenuIconResult.Success;
visitedMenus.Add(menu);
foreach (VRCExpressionsMenu.Control control in menu.controls)
{
@ -224,7 +227,7 @@ namespace nadena.dev.modular_avatar.core.editor
// SubMenu
if (control.type != VRCExpressionsMenu.Control.ControlType.SubMenu) continue;
ValidateExpressionMenuIconResult subMenuResult = ValidateExpressionMenuIcon(control.subMenu);
ValidateExpressionMenuIconResult subMenuResult = ValidateExpressionMenuIcon(control.subMenu, visitedMenus);
if (subMenuResult != ValidateExpressionMenuIconResult.Success) return subMenuResult;
}