[ShaderGraph] [2022.1] Fix for exception thrown when changing packages with embedded subgraphs #5441
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Purpose of this PR
Fixing an issue I ran into, where sometimes the subgraph asset is destroyed, and we don't remove it from the cached list before attempting to access it. This PR just adds a check to ignore the cache entry if it has been destroyed.
As far as I can tell, this is triggered when I have a package mapped to a repo, that contains a subgraph, and I sync the repo (with a subgraph asset deletion) while Unity is running. ShaderGraph seems to run this code before the removing the deleted asset from the list, resulting in an exception being thrown when the asset is accessed -- the exception borks ShaderGraph, making it unoperational.
Testing status
Tested against the repro steps above (changing package version). The PR fixes the issue.
Yamato:
ShaderGraph PR Job: https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/sg%252Ffix%252Fsearch-window-exception/.yamato%252Fall-shadergraph.yml%2523PR_ShaderGraph_2021.2/8407608/job
Comments to reviewers
Notes for the reviewers you have assigned.