Search Unity

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:
    412
    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)
     
  2. ballistic_cowboy

    ballistic_cowboy

    Joined:
    Jun 30, 2018
    Posts:
    19
    I have encountered the same problem, it's pretty annoying - did you manage to sort out a fix in the end?
     
  3. daxiongmao

    daxiongmao

    Joined:
    Feb 2, 2016
    Posts:
    412
    I am not sure of the exact solution. But i think i just delay a frame.
    I had a component on the Cinemachine brain. That in its OnEnable it would try to disable the Post Process Layer.
    So now it starts a coroutine that waits one frame so the Postprocess layer has a chance to initialize first.

    I am pretty sure that is my fix. I would have to go back and review more if that doesn't help for you.

    This works and performance seems ok having profiled it some. I did it this way instead of modifying Cinemachine code hoping they would of seen this and maybe fixed it.

    Doing frame captures on iOS at least the extra textures etc are not there.
     
  4. daxiongmao

    daxiongmao

    Joined:
    Feb 2, 2016
    Posts:
    412
    I am hitting this again. Inside the prefab editor i have cameras that are causing this same thing to happen again.
     
  5. WGustavo

    WGustavo

    Joined:
    Mar 11, 2022
    Posts:
    1
    I was able to solve this issue by forcing a bundles re-init on the post process layer during awake:
    Code (CSharp):
    1. postProcessLayer.InitBundles();
     
    emanutav and danielstori like this.