Why does this happen?

Press up to see the error while in debug mode.

Looks like the fog sprite is being accessed before assignment, here:

Error message is not helpful in this case. I’ll file a GitHub issue to improve it.