- Home /
Unity4 crashes with 1.5M of cubes using MeshTopology
Hi,
I was working with meshTopology for the creation of triangles to make cubes, but when I try to create 1.5M of cubes the editor crashes.
Do you know what could be the problem, or how can I create all these cubes?
I got this in the log file:
d3d11: failed to create vertex buffer of size 1056 [0x887A0005] d3d11: failed to create index buffer of size 108 [0x887A0005] d3d11: failed to create vertex buffer of size 1248 [0x887A0005] d3d11: failed to create index buffer of size 132 [0x887A0005] d3d11: failed to create vertex buffer of size 576 [0x887A0005] d3d11: failed to create index buffer of size 60 [0x887A0005] d3d11: failed to create vertex buffer of size 1632 [0x887A0005] d3d11: failed to create index buffer of size 168 [0x887A0005] d3d11: failed to create 2D texture id=455 w=16 h=16 mips=1 d3dfmt=28 [887a0005] d3d11: failed to create 2D texture view id=455 [80070057] failed to create 2D texture
Do you think, that this could be the problem?
Because, if I can create 40M of point without problem with Topology, theorically, 1.5M of cubes should work, isn't it?
thank you
rp
You need to be more clear what you are trying to do. Are you trying to combine cube vertices for a voxel based game like $$anonymous$$inecraft? Unity has an arbitrary max limit on the vertex count per $$anonymous$$eshFilter, but I suspect that isn't your problem. If you are trying to add a number of cubes involving the word "million" to a single vertex buffer you are doing something wrong...
To me that looks like you just reached your grafics card memory limit. $$anonymous$$eep in $$anonymous$$d that it depends on the vertex format Unity use how much memory a single vertex will need. I'm not sure what exact formats Unity will use, but it's possible to store the position as 3 or 4 floats. Same story for normals, tangents, binormals, color, texture coordinates. You can easily get a vertex format size of 10 to 30 float values which are 40 to 120 bytes per vertex. To store 1$$anonymous$$ vertices you would need 40 to 120 $$anonymous$$B. In addition you have your Textures (probably with mipmaps) alignment overhead index buffers.
It's really hard to tell what's the exact problem in this case without more details on what your building (maybe at least some code fragments) and on what hardware you run this.
You don't need $$anonymous$$eshTopology if you're using triangles. Just do it the usual way. $$anonymous$$eshTopology is for Quads, Lines, etc.
No, its working for 1$$anonymous$$, but it crashes when I go further than 1.5 or 2$$anonymous$$ of cubes. $$anonymous$$y cubes are ok. It's just that I thought that the limit was better than this...
As i said, the limit depends on the hardware you're using as well as on the vertex format that Unity will use. The vertex format depends on what things you setup for your mesh (vertices, normals, colors, uv, uv2, tangents). In addition the index buffer also need some space just in case of 1$$anonymous$$ triangles (3$$anonymous$$ indices) it's another 6$$anonymous$$B (16bit indices).
Answer by Alec Thilenius · Dec 19, 2012 at 08:09 PM
Hmmm. Again, not a ton a detail, but ill do my best. You need to remember that a vertex only defines a point in space. Then you have what are called index buffers that 'wind' the points together into triangles. Now depending on how you make the cube, you will have 8 to 36 verticies per cube. Assuming you make the cube correct this puts you RIGHT at the 65000 vert limit. THEN you have to wind the verts together, and you need 3 entries in a vertex buffer to define one triangle. It sounds like what you are trying to do is very non-trivial. Take a look at: http://en.wikipedia.org/wiki/Marching_cubes and search the forums for questions related to Vexel games. This do exactly what you are talking about.
Sorry I wasn't clear, no what I'm trying to do is to create the maximum possible number of cubes for a visualization project. To do that, I was using $$anonymous$$eshTopology to create my cubes using triangles. A GameObject has a 65000 vertex limit, so I was just trying to create simple cubes with 8 vertices, so per GameObject I have 8125 cubes. So using 185 GameObjects I could have the 1.5$$anonymous$$. But it looks that something is wrong...
when I draw the points using $$anonymous$$eshTopology, I can have 40$$anonymous$$ of points doing the same thing and I thought that I could have at least 5$$anonymous$$ of cubes if I respect the vertex limit...
Any idea what could be wrong?