- Home /
What is the recommended pattern when using ComputeBuffer with SRP?
I'm using a compute buffer to send 2000+ vector3 to a fragment shader in a ScriptableRenderPass, it works but I get a lot of memory leak warnings like:
GarbageCollector disposing of ComputeBuffer allocated in ... .cs at line XX.
Please use ComputeBuffer.Release() or .Dispose() to manually release the buffer. UnityEngine.ComputeBuffer:Finalize()
My earlier code tried to set the buffer and then Release() it at the end Execute() in a ScriptableRenderPass which didn't work. After a lot of trial and error and realized the I Released it before the shader had a chance to access it. Subquestion: Is a compute buffer passed as a ref and an array as a value?
Back to the original question. My current implementation basically sets the buffer as a class property of the ScriptableRenderPass and releases it just before I'm updating it. ScriptableRenderPass also implements IDisposable so a second release is called (if needed) on Dispose.
So I think I have my bases covered, but I still get the warnings mentioned above.
I can't find any relevant samples covering how to user ComputeBuffer in SRP.
Your answer
Follow this Question
Related Questions
Changing two different objects renderer colour 1 Answer
Renderer.materials leaking materials 1 Answer
Changing the materials in Editor Mode Without Getting the leak Error 3 Answers
Why does my materials get destroyed on some persistant objects ? 2 Answers
Is there any command that can reference deactivated objects? 1 Answer