Skip to content

Commit bce62e4

Browse files
april-roszkowskiEvergreen
authored andcommitted
[Port][6000.4][UUM-134265] Fix NullReferenceException when deleting shader input categories
1 parent c0d8603 commit bce62e4

1 file changed

Lines changed: 32 additions & 24 deletions

File tree

  • Packages/com.unity.shadergraph/Editor/Data/Graphs

Packages/com.unity.shadergraph/Editor/Data/Graphs/GraphData.cs

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,40 +1671,49 @@ public ShaderInput AddCopyOfShaderInput(ShaderInput source, int insertIndex = -1
16711671
return copy;
16721672
}
16731673

1674-
public void RemoveGraphInput(ShaderInput input)
1674+
// Removes a collection of shader inputs, deferring graph validation until all inputs have been removed
1675+
public void RemoveGraphInputs(IEnumerable<ShaderInput> inputs)
16751676
{
1676-
switch (input)
1677+
foreach (ShaderInput input in inputs)
16771678
{
1678-
case AbstractShaderProperty property:
1679-
var propertyNodes = GetNodes<PropertyNode>().Where(x => x.property == input).ToList();
1680-
foreach (var propertyNode in propertyNodes)
1681-
ReplacePropertyNodeWithConcreteNodeNoValidate(propertyNode);
1682-
break;
1683-
}
1679+
switch (input)
1680+
{
1681+
case AbstractShaderProperty property:
1682+
var propertyNodes = GetNodes<PropertyNode>().Where(x => x.property == input).ToList();
1683+
foreach (var propertyNode in propertyNodes)
1684+
ReplacePropertyNodeWithConcreteNodeNoValidate(propertyNode);
1685+
break;
1686+
}
16841687

1685-
// Also remove this input from any category it existed in
1686-
foreach (var categoryData in categories)
1687-
{
1688-
if (categoryData.IsItemInCategory(input))
1688+
// Also remove this input from any category it existed in
1689+
foreach (var categoryData in categories)
16891690
{
1690-
categoryData.RemoveItemFromCategory(input);
1691-
break;
1691+
if (categoryData.IsItemInCategory(input))
1692+
{
1693+
categoryData.RemoveItemFromCategory(input);
1694+
break;
1695+
}
16921696
}
1693-
}
16941697

1695-
foreach(var node in GetNodes<SubGraphNode>())
1696-
{
1697-
if (node.UsedReferenceNames().Contains(input.referenceName))
1698+
foreach (var node in GetNodes<SubGraphNode>())
16981699
{
1699-
node.ValidateNode();
1700-
node.Dirty(ModificationScope.Graph);
1700+
if (node.UsedReferenceNames().Contains(input.referenceName))
1701+
{
1702+
node.ValidateNode();
1703+
node.Dirty(ModificationScope.Graph);
1704+
}
17011705
}
1702-
}
17031706

1704-
RemoveGraphInputNoValidate(input);
1707+
RemoveGraphInputNoValidate(input);
1708+
}
17051709
ValidateGraph();
17061710
}
17071711

1712+
public void RemoveGraphInput(ShaderInput input)
1713+
{
1714+
RemoveGraphInputs(new ShaderInput[] { input });
1715+
}
1716+
17081717
public void MoveCategory(CategoryData category, int newIndex)
17091718
{
17101719
if (newIndex > m_CategoryData.Count || newIndex < 0)
@@ -1889,8 +1898,7 @@ public void RemoveCategory(string categoryGUID)
18891898
m_RemovedCategories.Add(existingCategory);
18901899

18911900
// Whenever a category is removed, also remove any inputs within that category
1892-
foreach (var shaderInput in existingCategory.Children)
1893-
RemoveGraphInput(shaderInput);
1901+
RemoveGraphInputs(existingCategory.Children);
18941902
}
18951903
else
18961904
AssertHelpers.Fail("Attempted to remove a category that does not exist in the graph.");

0 commit comments

Comments
 (0)