I have this code updating a 10x10 texture:
Assert.AreEqual(tileTypeTex.format, TextureFormat.RG16);
NativeArray<byte> colors = new(2 * TEXTURE_RES * TEXTURE_RES, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
int idx = 0;
int xyMax = TEXTURE_RES - 1;
for (int ty = -1; ty < xyMax; ty++)
{
for (int tx = -1; tx < xyMax; tx++)
{
int lx = blockData.x + tx;
int ly = blockData.y + ty;
var tilePtr = tilemap.TryGetPtr(lx, ly);
var color = GetTileColor(tilePtr);
colors[idx++] = (byte)(color.r);
colors[idx++] = (byte)(color.g);
}
}
tileTypeTex.SetPixelData(colors, 0);
tileTypeTex.Apply();
Right after this code, there is code updating meshes, for which data has been previously allocated inside a job with Allocator.TempJob. This mesh update code starts generating errors like this:
Failed setting triangles. Some indices are referencing out of bounds vertices. IndexCount: 12, VertexCount: 8
The erroneous indices are not deterministic.
If I change the allocator for the colors array to Allocator.TempJob allocator, there is no issue! Is this a facepalm moment? Or is there something peculiar with temp or temp job allocations that I don't know about?
