Skip to content

Commit

Permalink
Merge pull request #18 from innogames/stackoverflowexception-fix
Browse files Browse the repository at this point in the history
Fixed possible StackOverflowException in GetAllReachableNodes function
  • Loading branch information
pak762 authored Nov 10, 2022
2 parents 6674b50 + edf605c commit 2efe354
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
21 changes: 11 additions & 10 deletions AssetRelationsViewer/Editor/AssetRelationsViewerWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1139,8 +1139,8 @@ private void ReloadContext(ResolverUsageDefinitionList resolverUsageDefinitionLi
LoadDependencyCache(resolverUsageDefinitionList, _updateCache, partialUpdate);
ChangeSelection(_selectedNodeId, _selectedNodeType);
}
private void GetAllReachableNodes(Node node, HashSet<Node> reachedNodes, HashSet<Node> newNodes)

private void GetAllReachableNodes(Node node, HashSet<Node> reachedNodes, HashSet<Node> newNodes, RelationType relationType)
{
if (reachedNodes.Contains(node))
{
Expand All @@ -1150,15 +1150,9 @@ private void GetAllReachableNodes(Node node, HashSet<Node> reachedNodes, HashSet
reachedNodes.Add(node);
newNodes.Add(node);

GetAllReachableNodes(node, reachedNodes, newNodes, RelationType.DEPENDENCY);
GetAllReachableNodes(node, reachedNodes, newNodes, RelationType.REFERENCER);
}

private void GetAllReachableNodes(Node node, HashSet<Node> reachedNodes, HashSet<Node> newNodes, RelationType relationType)
{
foreach (Connection connection in node.GetRelations(relationType))
{
GetAllReachableNodes(connection.Node, reachedNodes, newNodes);
GetAllReachableNodes(connection.Node, reachedNodes, newNodes, relationType);
}
}

Expand All @@ -1170,7 +1164,14 @@ private void CalculateAllNodeSizes(Node rootNode)
}

HashSet<Node> newNodes = new HashSet<Node>();
GetAllReachableNodes(rootNode, _nodeSizesReachedNodes, newNodes);
HashSet<Node> referencerNodes = new HashSet<Node>();

GetAllReachableNodes(rootNode, referencerNodes, referencerNodes, RelationType.REFERENCER);

foreach (Node referencerNode in referencerNodes)
{
GetAllReachableNodes(referencerNode, _nodeSizesReachedNodes, newNodes, RelationType.DEPENDENCY);
}

List<Node> allNodes = newNodes.ToList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class AssetToFileDependency
// Cache to find get mapping of assets to the file the asset is included in
public class AssetToFileDependencyCache : IDependencyCache
{
private const string Version = "1.4.5";
private const string Version = "1.5.1";
private const string FileName = "AssetToFileDependencyCacheData_" + Version + ".cache";

private Dictionary<string, GenericDependencyMappingNode> _fileNodesDict = new Dictionary<string, GenericDependencyMappingNode>();
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
**1.5.1**
- Increase serialize version of AssetToFileDependencyCache because of dependency order change
- Fixed possible StackOverflowException with very huge dependency trees and ShowAdditionalInformation option being enabled

**1.5.0**
- AssetDependencyCache update is now a lot faster due to improved reflection code
- "Calculating all node sizes" step is now faster since it now only calculates reachable nodes
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "com.innogames.asset-relations-viewer",
"displayName": "Asset Relations Viewer",
"description": "Editor UI for displaying dependencies between assets in a tree based view",
"version": "1.5.0",
"version": "1.5.1",
"unity": "2018.4",
"license": "MIT",
"repository": {
Expand Down

0 comments on commit 2efe354

Please sign in to comment.