Any reference to pixelGrid through pixelGrid[#][#] makes the code stop working. I've declared pixelGrid in several different ways, without any improvement. Assigning 0 to a value and showing it works, but assigning pixelGrid[0][0], also equal to 0, abruptly breaks things at that point. It doesn't matter whether I access the array in a condition, to update a value, or elsewhere.
var pixelGrid;
for (let row = 0; row < 9; row++) {
for (let column = 0; column < 9; column++) {
pixelGrid[row][column] = 0;
}
}
function redrawPixels() {
// Shortened for simplicity
ImageData.data[0] = 0; // Works fine.
ImageData.data[0] = pixelGrid[0][0]; // Function stops, and ctx.putImageData no longer updates canvas.
}