cakeslice / Outline-Effect

Outline Image Effect for Unity
MIT License
1.48k stars 201 forks source link

Memory leak with NatCorder #40

Closed ponahoum closed 3 years ago

ponahoum commented 5 years ago

I use your plugin with the asset NatRecorder (a plugin that records the screen). It seems that in certain condition, OutlineEffect causes a memory leak when recording the screen with NatCorder. I found a quick fix to this issue, maybe you can tell me more about it. It seems than erasing rendertexture with the new renderTexture doesn't destroys the old one in the memory

if (renderTexture == null || renderTexture.width != sourceCamera.pixelWidth || renderTexture.height != sourceCamera.pixelHeight) {
 Destroy(renderTexture); // Added line
 renderTexture = new RenderTexture(sourceCamera.pixelWidth, sourceCamera.pixelHeight, 16, RenderTextureFormat.Default);
 extraRenderTexture = new RenderTexture(sourceCamera.pixelWidth, sourceCamera.pixelHeight, 16, RenderTextureFormat.Default);
 outlineCamera.targetTexture = renderTexture;
}