Fix a bug where an incorrect number of terrain segments are being generated.
Fix a bug where an incorrect number of terrain segments are being generated.

This commit also fixes an issue where more memory than required is being allocated.

mackron/openta,mackron/openta