Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Bug NullReferenceException in 2022.2.1f1/URP 14.0.4 when rendering the Inspector preview window

Discussion in 'Universal Render Pipeline' started by ElliotB, Dec 21, 2022.

  1. ElliotB

    ElliotB

    Joined:
    Aug 11, 2013
    Posts:
    218
    Hi,

    I'm experiencing a tonne of spam in the console whenever the Inspector window redraws. I'm using a custom render feature. The game view and scene view are fine, no bugs, but my console gets flooded with these messages:

    Code (csharp):
    1. ArgumentNullException: Value cannot be null.
    2. Parameter name: value
    3. UnityEngine.MaterialPropertyBlock.SetTexture (System.Int32 nameID, UnityEngine.Texture value) (at <bdd20210bb844b2e88e1149ea99da5ef>:0)
    4. UnityEngine.Rendering.Blitter.BlitTexture (UnityEngine.Rendering.CommandBuffer cmd, UnityEngine.Rendering.RTHandle source, UnityEngine.Vector4 scaleBias, UnityEngine.Material material, System.Int32 pass) (at Library/PackageCache/com.unity.render-pipelines.core@14.0.4/Runtime/Utilities/Blitter.cs:238)
    5. UnityEngine.Rendering.Blitter.BlitTexture (UnityEngine.Rendering.CommandBuffer cmd, UnityEngine.Rendering.RTHandle source, UnityEngine.Vector4 scaleBias, System.Single mipLevel, System.Boolean bilinear) (at Library/PackageCache/com.unity.render-pipelines.core@14.0.4/Runtime/Utilities/Blitter.cs:191)
    6. UnityEngine.Rendering.Blitter.BlitCameraTexture (UnityEngine.Rendering.CommandBuffer cmd, UnityEngine.Rendering.RTHandle source, UnityEngine.Rendering.RTHandle destination, System.Single mipLevel, System.Boolean bilinear) (at Library/PackageCache/com.unity.render-pipelines.core@14.0.4/Runtime/Utilities/Blitter.cs:306)
    7. ProPixelizer.PixelizationPass.Execute (UnityEngine.Rendering.ScriptableRenderContext context, UnityEngine.Rendering.Universal.RenderingData& renderingData) (at Assets/ProPixelizer/SRP/ProPixelizerPixelizationPass.cs:245)
    each one is accompanied by the following message:
    Code (csharp):
    1. Assertion failed
    2. UnityEngine.Rendering.Blitter:BlitCameraTexture (UnityEngine.Rendering.CommandBuffer,UnityEngine.Rendering.RTHandle,UnityEngine.Rendering.RTHandle,single,bool)
    3. ProPixelizer.PixelizationPass:Execute (UnityEngine.Rendering.ScriptableRenderContext,UnityEngine.Rendering.Universal.RenderingData&) (at Assets/ProPixelizer/SRP/ProPixelizerPixelizationPass.cs:245)
    4. UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
    The errors are also accompanied by warnings:
    Code (csharp):
    1. Internal: JobTempAlloc has allocations that are more than the maximum lifespan of 4 frames old - this is not allowed and likely a leak
    Code (csharp):
    1. To Debug, run app with -diag-job-temp-memory-leak-validation cmd line argument. This will output the callstacks of the leaked allocations.
    Presumably because the rendering crashed out before native resources could be de'alloc'ed.

    upload_2022-12-21_17-3-4.png
    Every draw call, so there's a few hundred every second.

    I know it is the Inspector window that is causing these errors because:
    • They only occur when a mesh or material is selected (ie, when a draw occurs).
    • Putting the inspector window into Debug mode (so no preview is drawn) completely removes the error and it no longer occurs.
    The error does not occur before URP14.

    Where is the exception raised?

    In execute my Pass does the following:
    Code (CSharp):
    1. RTHandle ColorTarget = renderingData.cameraData.renderer.cameraColorTargetHandle;
    2. ...
    3. Blitter.BlitCameraTexture(buffer, ColorTarget, _OriginalScene);
    ...following through
    Code (CSharp):
    1.        public static void BlitCameraTexture(CommandBuffer cmd, RTHandle source, RTHandle destination, float mipLevel = 0.0f, bool bilinear = false)
    2.        {
    3.            Vector2 viewportScale = source.useScaling ? new Vector2(source.rtHandleProperties.rtHandleScale.x, source.rtHandleProperties.rtHandleScale.y) : Vector2.one;
    4.            // Will set the correct camera viewport as well.
    5.            CoreUtils.SetRenderTarget(cmd, destination);
    6.            BlitTexture(cmd, source, viewportScale, mipLevel, bilinear);
    7.        }
    line 191:
    Code (CSharp):
    1.         public static void BlitTexture(CommandBuffer cmd, RTHandle source, Vector4 scaleBias, float mipLevel, bool bilinear)
    2.         {
    3.             s_PropertyBlock.SetFloat(BlitShaderIDs._BlitMipLevel, mipLevel);
    4.             BlitTexture(cmd, source, scaleBias, GetBlitMaterial(TextureXR.dimension), bilinear ? 1 : 0);
    5.         }
    line 238:
    Code (CSharp):
    1.         public static void BlitTexture(CommandBuffer cmd, RTHandle source, Vector4 scaleBias, Material material, int pass)
    2.         {
    3.             s_PropertyBlock.SetVector(BlitShaderIDs._BlitScaleBias, scaleBias);
    4.             s_PropertyBlock.SetTexture(BlitShaderIDs._BlitTexture, source);
    5.             DrawTriangle(cmd, material, pass);
    6.         }
    The exception is being thrown on the s_PropertyBlock.SetTexture(BlitShaderIDs._BlitTexture, Source), in an internal function I cannot see the source of.

    What is the cause?

    I was able to debug this using a breakpoint and found something unexpected. The Source for my blit is ColorTarget, and the target is _OriginalScene. This is what both of these look like:

    _OriginalScene:
    upload_2022-12-21_17-10-25.png

    ColorTarget:
    upload_2022-12-21_17-10-39.png


    ColorTarget (the 'source' RTHandle argument in the blit method) is not null, but appears to be uninitialized.

    (I have to do it this way so I can swap the ColorTarget definition with a define statement, as earlier URP versions did not support this variable or called it something else).

    The bug:

    In URP 14 the cameraColorTargetHandle is now uninitialised when rendering the Inspector window. This behavior is different to URP 13, where the variable was properly intialised. This bug breaks custom post processes that blit using cameraColorTargetHandle and prevents custom passes from working in the inspector window.
     
  2. knowlife4

    knowlife4

    Joined:
    Jan 6, 2014
    Posts:
    3
    I'm experiencing this same issue, any clue on a temporary work around?
     
  3. ElliotB

    ElliotB

    Joined:
    Aug 11, 2013
    Posts:
    218
    No, all you can do for now is disable your render feature in the preview window by checking camera type.
     
  4. clabbe

    clabbe

    Joined:
    Aug 9, 2013
    Posts:
    23
    using UnityEngine.2022.2.6f1;

    I put a RenderTargetIdentifier as destination instead (you can keep source a regular RTHandle). it seems to me that there is a bug when setting the name of the RTHandler or when the Blitter is getting the RTHandle.name.

    i've been struggling with this for couple of days now and this is as far as i've come:
    Code (CSharp):
    1.  
    2. RenderTargetIdentifier destination;
    3. int destinationID = Shader.PropertyToID("_Destination");
    4.  
    5. public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
    6. {
    7.      destination = new RenderTargetIdentifier(destinationID);
    8. }
    9.  
    10. public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
    11. {
    12.      cmd.GetTemporaryRT(destinationID, descriptor, FilterMode.Bilinear);
    13. }
    14.  
    15. public override void OnCameraCleanup(CommandBuffer cmd)
    16. {
    17.      cmd.ReleaseTemporaryRT(destinationID);
    18. }

    It works but it will give you this in the console:
    'Assets\Scripts\Rendering\Custom Render Pipeline Assets\Templates\TemplatePass.cs(105,13): warning CS0618: 'ScriptableRenderPass.Blit(CommandBuffer, RenderTargetIdentifier, RenderTargetIdentifier, Material, int)' is obsolete: 'Use RTHandles for source and destination'


    I hope it helps!