- Home /
int array overflow exception
Hey guys, simple issue here although I don't understand where its coming from. I make an int array for a procedural mesh but when creating the array it throws me an overflow exception. the code :
int MeshLength = Points.Count;
int[] Triangles = new int[(MeshLength * 3) + ((MeshLength - 1) * 12)];
MeshLength has a maximum value of 99 and a minimum value of 1. Therefore, the maximum index of this array is 1473 ( 99*3 = 297, 98*12 = 1176, 1176 + 297 = 1473 ).
At the beginning I thought the error came from MeshLength int sometimes being 0, but since then fixed that and it didn't get rid of the error. Contextual code does not influence this array.
You need to post the part where you use the Triangles. Obviously, the overflow error is being thrown there not at the initialization.
Answer by alireza97 · Sep 16, 2019 at 08:03 AM
I think you might fixed 'MeshLength ' in the wrong place because when I fixed it in Awake or make it Serializable and fixed it in my editor it works.
this is when Points size is 0:
.
and when I fixed it in my editor :
Yep, actually my Points list was shared by two different objects and I Clear() it on one of the objects, making it empty on the other as well, thus giving a 0 index for $$anonymous$$eshLength. Thanks for confir$$anonymous$$g it was a problem with 0.