Fixed crash when capturing terrain outside of the map

Fixes #726.
Removed commented code