Search Issue Tracker

Fixed in 2018.2.12f1

Votes

0

Found in

2017.3.1p2

Issue ID

1044784

Regression

No

PostProcessStack v2: PostProcessManager.instance.QuickVolume example code throws NullRef exception

Scripting

-

The documentation for the Post Processing Stack shows the recommended way to create and destroy PostProcessVolumes through code at runtime (https://github.com/Unity-Technologies/PostProcessing/wiki/Manipulating-the-Stack). In the example class VignettePulse, the author uses the function PostProcessManager.instance.QuickVolume to create a PostProcessVolume with a Vignette effect. Internally, this function allocates a new GameObject, a PostProcessVolume component, and a PostProcessProfile. The author then demonstrates that you should destroy volumes created in this manner by calling RuntimeUtilities.DestroyVolume, passing in the volume and 'true' to destroy the profile and its associated PostProcessSettings.

To reproduce:
1. Download project from the attached link and open in Unity
2. Open "scene" scene
3. Enter Play mode
4. Press space button
5. Observe that in Console there will be printed error:

"NullReferenceException: Object reference not set to an instance of an object
UnityEngine.Rendering.PostProcessing.RuntimeUtilities.DestroyProfile (UnityEngine.Rendering.PostProcessing.PostProcessProfile profile, Boolean destroyEffects) (at Assets/PostProcessing-2/PostProcessing/Runtime/Utils/RuntimeUtilities.cs:495)
UnityEngine.Rendering.PostProcessing.RuntimeUtilities.DestroyVolume (UnityEngine.Rendering.PostProcessing.PostProcessVolume volume, Boolean destroySharedProfile) (at Assets/PostProcessing-2/PostProcessing/Runtime/Utils/RuntimeUtilities.cs:505)
NewBehaviourScript.Destroy () (at Assets/NewBehaviourScript.cs:28)
NewBehaviourScript.Update () (at Assets/NewBehaviourScript.cs:23)"

Notes:
- This issue reproduces on Windows and OSX
- Link to the project is in the Comments section
- The function throws a NullReferenceException when called in this way since the sharedProfile field is null for volumes created with QuickVolume. Shouldn't this function instead destroy the m_InternalProfile?
- The function does not destroy the GameObject allocated by the QuickVolume function. Because the example code in the VignettePulse class doesn't show that you manually have to destroy the GameObject yourself, it would be expected that this function handle that.
- As an aside, there is also a bug with the example VignettePulse class. The class implements a function called 'Destroy', when the author probably meant 'OnDestroy', meaning that this function won't ever actually be called by Unity. I imagine this is why the bugs with RuntimeUtilities.DestroyVolume was not caught sooner.

Reproduced on Unity 2017.1.4f1, 2017.2.3p1, 2017.3.2f1, 2017.4.5f, 2018.1.4f1, 2018.2.0b7 and 2018.3.0a1

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.