cakeslice / Outline-Effect

Outline Image Effect for Unity

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

It causes memory usage getting higher.

OpenLevel opened this issue · comments

thanks for your share and sorry for my bad English.

I applied this to my project and worked greatly.(It uses Mesh Renderer.)
However, the memory usage was getting higher up to 2GB.

OutlineEffect creates garbage per frame.

Per frame allocations OnPreCull:
if (outlineRenderers.Distinct().Count() < outlineRenderers.Count)

originalMaterials = new Material[outlineRenderers.Count];
originalLayers = new int[outlineRenderers.Count];

outlineRenderers[i].material.mainTexture = originalMaterials[i].mainTexture;

originalEraseMaterials = new Material[eraseRenderers.Count];
originalEraseLayers = new int[eraseRenderers.Count];

eraseRenderers[i].material.mainTexture = originalEraseMaterials[i].mainTexture;

renderTexture = RenderTexture.GetTemporary(width, height, 16, RenderTextureFormat.Default);
Temporary texture is optimized. but you can prepare a texture.
#8

I've fixed above memory leaks.

outlineRenderers[i].material.mainTexture = originalMaterials[i].mainTexture;
eraseRenderers[i].material.mainTexture = originalEraseMaterials[i].mainTexture;
I changed material.mainTexture to sharedMaterial.mainTextrue
then the memory leaking is stopped but it dose not work properly.
needs some fix

--solved--
If you use Mesh Renderer, need an extra Outline Renderer per sharedMaterial.
you should create and prepare materials for it on startup. otherwise, it occur memory leaks.
I'm going to commit fixed codes later.
#8's code still has some problems.

Thanks! I merged your fixes and went ahead and changed the code to be "Outline" component based which makes more sense