- Home /
How to avoid Memory allocation on procedural Mesh generation
Hi everybody,
i toyed around with a little Hexagon-Voxel thing in Unity, and everything is working fine - except for some framerate hickups caused by CG. I also found the problem - my terrain is divided in chunks (as usual when rendering Voxels) and with each chunk mesh-change my program allocates nearly half a MB of ram - which is of course not good. The profiler tells me that all of these memory allocation is caused by copying my vertex, triangle, uv etc. data from list to Array. (list.ToArray() call). This is because i have some lists for vertices, triangles, uvs etc. which i fill in my CalcMesh routine based on my voxel data.
I can't use static size arrays because i don't know how many vertices/triangles etc. the mesh will have. Is there any strategy/trick/hack/whatever to avoid the list and work with something, which does not allocate this much memory?
I hope i could describe what i mean, and i hope for any ideas or solutions!
@misterPantoni Did you ever figure this out? I'd love to know the same answer and have the same issue.
Answer by RuinsOfFeyrin · Nov 20, 2015 at 03:45 AM
Hello,
I actually posted something on this a few days ago in another question.
As far as i can tell this is a bug in unity. There is an entry in the issue tracker on the unity website for version 5.3 that mentions fixing of a memory leak in procedural mesh generation. The memory leak is evident in the example for procedural mesh generation in the unity documentation itself.
http://issuetracker.unity3d.com/issues/meshapi-memory-leak-with-procedural-mesh
Hope that helps.
Your answer
