The grid was pointer was moved to the next element at every loop, which made `vi.grid` and `vi.mask` disagree. Instead, iterate the grid before accessing data, so the pointers agree. To avoid unrolling the first loop iteration or adding a branch for the first iteration, start the grid at a -1 offset. Pull Request: https://projects.blender.org/blender/blender/pulls/113015