Thank you for that - that is helpful. What it appears was happening was that gr was being set from an invalid tile (-1, 185), and so was becoming NULL. This was because nothing in the code constrained the tile to one within the map. I have added code so constraining it, so now it does not crash, and, unlike the simple solution of simply checking whether gr is NULL, also does not prevent the factory smoke from working. The smoke does not move as much as it would in a different position, but this is preferable either to crashing or there being no smoke at all.
I should be grateful if you could re-test with the latest version on the master branch. Thank you.