Custom Terrain Generation


Changes how land and water are generated. Highly customizable.

11 months ago
0.16 - 1.1
1.66K
Environment

g Non-recoverable error in Maze1 pattern

5 years ago
(updated 5 years ago)

Hi erst,
A friend and I were setting up a Maze map in and run into the following error.
It is easily reproducible as it occurs when you attempt to explore the map.
Versions:
- Factorio: v0.17.32
- ctg: v0.4.2

Reproduction steps:
- Disable all mods except for ctg
- New game; set terrain to Maze1 (fibonacci); no custom pattern required; for faster repro disable "big scan"
- Save game (if you want to test with "big scan", wait for map/scan to finish generating)
- Load saved game
-> Error occurs if "big scan" not used
-> If "big scan" option was selected, our experience is that the same error will occur when you attempt to move outside the explored area

Stacktrace:


Error while running event ctg::on_chunk_generated (ID 12)
ctg/patterns/maze1.lua:107: attempt to get length of local 'b' (a nil value)
stack traceback:
ctg/patterns/maze1.lua:107: in function 'expand'
ctg/patterns/maze1.lua:224: in function <ctg/patterns/maze1.lua:219>
(...tail calls...)
ctg/patterns/transforms.lua:28: in function 'lg'
ctg/patterns/patterns.lua:129: in function 'gt'
ctg/control.lua:56: in function <ctg/control.lua:28>


Save files can be provided on request.
Other mods are being used but we have tested repro steps when they are disabled - error still occurs.

5 years ago

Hi Erst,

With a bit of debugging, the underlying error appears to be in patterns/maze1.lua:52
We think this line should read:
data.values = values

We noted that the save files weren't storing the true/false values for land/void, and traced it here. In our local dev copy of the mod this change appears to be stable. It doesn't fix existing saves, but works for newly generated maps. To fix our existing save, we regenerated our map with the new code and same seed, and then manually modified our save file to include the values data.

Thanks for the mod and debugging puzzle! After looking at your code we are now very curious about the underlying logic for Maze1... and we might have a "Maze4" to contribute later. :)

5 years ago
(updated 5 years ago)

Thanks for the bug report, the detailed diagnosis, the fix, and the generosity to refer to it as a "debugging puzzle"! The fix is in version 0.4.3. I am relieved to see that the bug was introduced only recently, in 0.4.0.

I'm curious how you modified your save file, once you had recovered the data?

Maze1 was the very first pattern I had written, years ago in Factorio 0.12 (back when you could not cut corners diagonally across water), and I do not remember the details of how it works. I remember the underlying motivation was to make a maze with no 2x2 regions of the same tile type (except at the origin and in a few rare cases) and to make all land masses infinitely large. It grows in layers out from the origin. When there are N consecutive land tiles in the outer-most layer, it needs to randomly choose a new set of N tiles such that no two in a row are both land; the Nth Fibonacci number is the number of ways that can be chosen, and base Fibonacci is a way of uniquely writing a number using 1s and 0s where no two 1s can be consecutive. I believe the union-find data structure was used to keep track of which sets of tiles are connected to each other so that no land mass is cut off on all sides.

(I insisted on all landmasses being infinitely large because this was before Factorio had landfill.)

I would be interested in seeing any other maze suggestions!

New response