# Why if there's more than 255 in zSize or in xSise, the whole block breaks?

• (Maybe there's a man who can help me) I'm making an obstacle with this violin:

``````using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MeshCreatorV2 : MonoBehaviour
{
Mesh mesh;
Vector3[] vertices;
int[] triangles;
Vector2[] uv;
public float cellSize;
public int xSize;
public int zSize;

float sample;
public float multiplier;
public float perlinSize;
public float xOffset;
public float yOffset;
void Awake()
{
mesh = GetComponent&lt;MeshFilter&gt;().mesh;

MakeDiscreteProceduralGrid();
UpdateMesh();
}

private void Update()
{
if (Input.GetKeyDown(KeyCode.R))
{
MakeDiscreteProceduralGrid();
UpdateMesh();
}
}

void MakeDiscreteProceduralGrid()
{
vertices = new Vector3[(xSize + 1) * (zSize + 1)];
triangles = new int[xSize * zSize * 6];

for(int i = 0, z = 0; z &lt;= zSize; z++)
{
for (int x = 0; x &lt;= xSize; x++)
{
sample = Mathf.PerlinNoise(x * (cellSize / 10) * perlinSize + xOffset, z * (cellSize / 10) * perlinSize + yOffset);
vertices[i] = new Vector3(x * (cellSize / 10), sample * multiplier, z * (cellSize / 10));
i++;
}
}

int v = 0;
int t = 0;
for (int z = 0; z &lt; zSize; z++)
{
for (int x = 0; x &lt; xSize; x++)
{
triangles[t + 0] = v + 0;
triangles[t + 1] = v + xSize + 1;
triangles[t + 2] = v + 1;
triangles[t + 3] = v + 1;
triangles[t + 4] = v + xSize + 1;
triangles[t + 5] = v + xSize + 2;
v++;
t += 6;
}
v++;
}
}

void UpdateMesh()
{
mesh.Clear();

mesh.vertices = vertices;
mesh.triangles = triangles;
mesh.uv = uv;
mesh.RecalculateNormals();
}

}
``````

All the public variables I'm putting in an inspector. For any values in zSize and xSize from 0 to 255 inclusive, Perlin's normal and noise works well, but if one of these values or both values is 256 or higher, the barrier stops to normal sidewards and polygones that cross with other polygons (so not to be so).
On Unity, version 2019.4.32f1 made a mistake "Expanding invalid MinMaxAABB." There are no errors in the version of Unity 2021.2.1f1, but the bag and there are incorrectly constructed at values above 255.
Reference to the project:

• https://docs.unity3d.com/ScriptReference/Mesh-indexFormat.html

Description of the data form of the grid index buffer.

The index buffer may be 16-bit (supporting up to 65535 peaks) or 32-bit (supported to 4 billion peaks). Format default index - 16 battles as it requires less memory and memory capacity.

Please note that there is no support for the 32-bit GPU indices. Guaranteed on all platforms; for example, Android devices Mali-400 does not support them. Use 32-bit indices on such a platform will be recorded in the journal The warning message, and the grid won't be displayed.

Change indexFormat sets subMeshCount in unit and cleans index buffer.

2

2

2

2

2

2

2

2

2

2

2

2

2

2

2