Fix a null pointer deference and add common grid generation layout.

Signed-off-by: Jérôme Benoit <jerome.benoit@grenouille.com>