Fixed stack-smashing bug due to grid being allowed to be too large.

This is a weird one that I still need to investigate more, but for now
limiting the grid size to a max of 64x64 keeps things in check.