Logic issue with generating multiple chunks (Flattening a array and indexing it)

NOTE TO MODERATORS: THIS THREAD IS IN THE CORRECT PLACE. PLEASE READ IT AND DO NOT MOVE IT TO SHADERS, ITS NOT A SHADER PROBLEM. ITS A LOGIC ISSUE.

Hello! So I’m trying to make terrain using compute shaders instead of CPU, and it works just fine for one single chunk, but whenever I try to use more chunks it gives weird results.

One chunk:

CPU:

GPU:

Multiple chunks (This is where it breaks itself):

CPU:

GPU:

It seems that it didnt copy corectly, here is the original theaed: Compute shader flatten chunk terrain array and make the array 2D once it hits the CPU again