Search Unity

  1. The 2022.1 beta is now available for testing. To find out what's new, have a look at our 2022.1 beta blog post.
    Dismiss Notice

Bug PostProcessLayer ResetHistory crashes because m_Bundles is null.

Discussion in 'Image Effects' started by daxiongmao, Oct 28, 2021.

  1. daxiongmao

    daxiongmao

    Joined:
    Feb 2, 2016
    Posts:
    344
    I am adding code to be able disable and enable post processing effects based on device levels.
    I have not found anything built into the processing stack to make this easy.

    So my scripts are enabled and disabling various parts of the PP Stack and Cinemeachine.
    In order to actually remove all the command buffers from a camera when all the effects are turned off.
    You have to disable the Post Process Layer.

    I disable it in my scripts. But doing this on enable in my script is causing the PostProcessLayer::InitBundles to not be called. But the ResetHistory is being called every frame by Cinemachine Post Processing.
    And in the case of the InitBundles not being called the m_Bundles is null and generates an exception.

    There needs to be a null check there or by default m_Bundles should not be null and just an empty dictionary.
    I am hoping I can work around it by disabling things over a frame or two giving the Initbundles a chance to be called.

    Code (CSharp):
    1.        
    2. public void ResetHistory()
    3.         {
    4.             foreach (var bundle in m_Bundles)
    5.                 bundle.Value.ResetHistory();
    6.  
    7.             temporalAntialiasing.ResetHistory();
    8.         }
    9.  

    NullReferenceException: Object reference not set to an instance of an object
    UnityEngine.Rendering.PostProcessing.PostProcessLayer.ResetHistory () (at Library/PackageCache/com.unity.postprocessing@3.1.1/PostProcessing/Runtime/PostProcessLayer.cs:810)
    Cinemachine.PostFX.CinemachinePostProcessing.OnCameraCut (Cinemachine.CinemachineBrain brain) (at Library/PackageCache/com.unity.cinemachine@2.7.8/Runtime/PostProcessing/CinemachinePostProcessing.cs:223)
    UnityEngine.Events.InvokableCall`1[T1].Invoke (T1 args0) (at <9899854e5b05425ab27d31f737cde095>:0)
    UnityEngine.Events.UnityEvent`1[T0].Invoke (T0 arg0) (at <9899854e5b05425ab27d31f737cde095>:0)
    Cinemachine.CinemachineBrain.ProcessActiveCamera (System.Single deltaTime) (at Library/PackageCache/com.unity.cinemachine@2.7.8/Runtime/Behaviours/CinemachineBrain.cs:618)
    Cinemachine.CinemachineBrain.ManualUpdate () (at Library/PackageCache/com.unity.cinemachine@2.7.8/Runtime/Behaviours/CinemachineBrain.cs:368)
    Cinemachine.CinemachineBrain.LateUpdate () (at Library/PackageCache/com.unity.cinemachine@2.7.8/Runtime/Behaviours/CinemachineBrain.cs:325)
     
unityunity