Skip to content

NullReferenceException in ShaderModifyListener's OnPostprocessAllAssets #89

@dinhanhminh

Description

@dinhanhminh

Describe the bug / 描述你遇到的Bug
A clear and concise description of what the bug is. / 清晰描述你遇到的问题。

When trying to import shader from assets ending in ".shader" or ".shadergraph", ShaderModifyListener will also try to import "Packages/com.unity.shadergraph", leading to the shader asset being null. This will then throw an exception in ShaderPerfMonitor.ClearShaderPerfCache:L146 -> IOHelper.ClearShaderPerfCache:L209 because the catch block fails to resolve shader.name

To Reproduce / 复现步骤

  1. Reimport asset
  2. Look for error: "NullReferenceException: Object reference not set to an instance of an object"

Screenshots / 截图
NullReferenceException: Object reference not set to an instance of an object
LWGUI.IOHelper.ClearShaderPerfCache (UnityEngine.Shader shader) (at ./Library/PackageCache/com.jasonma.lwgui@0911a513e3b5/Editor/Helper/IOHelper.cs:209)
LWGUI.PerformanceMonitor.ShaderPerfMonitor.ClearShaderPerfCache (UnityEngine.Shader shader) (at ./Library/PackageCache/com.jasonma.lwgui@0911a513e3b5/Editor/PerformanceMonitor/ShaderPerfMonitor.cs:148)
ShaderModifyListener.OnPostprocessAllAssets (System.String[] importedAssets, System.String[] deletedAssets, System.String[] movedAssets, System.String[] movedFromAssetPaths) (at Assets/Editor/ShaderModifyListener.cs:22)
System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <1eb9db207454431c84a47bcd81e79c37>:0)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <1eb9db207454431c84a47bcd81e79c37>:0)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <1eb9db207454431c84a47bcd81e79c37>:0)
UnityEditor.AssetPostprocessingInternal.InvokeMethod (System.Reflection.MethodInfo method, System.Object[] args) (at :0)
UnityEditor.AssetPostprocessingInternal.PostprocessAllAssets (System.String[] importedAssets, System.String[] addedAssets, System.String[] deletedAssets, System.String[] movedAssets, System.String[] movedFromPathAssets, System.Boolean didDomainReload) (at :0)
UnityEditor.AssetPostprocessingInternal:PostprocessAllAssets(String[], String[], String[], String[], String[], Boolean)

Unity Version / Unity版本

  • 6000.3.9f1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions