Page 1 of 1

Recursive noise functions crash without erroring

Posted: Thu Mar 12, 2026 8:42 am
by braxbro
So, I was testing something to see if I could use recursion or something like it to do summation notation in the noise system because I was curious and it would make the port of ClaustOrephobic easier.

I discovered that if you make a recursive NamedNoiseFunction:
1. The game accepts it as valid if it is never called. It just loads silently without objection to your Nonsense.
2. The game silently crashes if it is called at what appears to be the end of data stage. No error, no angry messages in factorio-current.log - it just crashes to desktop.

Reproducing this is trivial. Write a recursive noise function such as the following:

Code: Select all

{
        type = "noise-function",
        name = "claustorephobic_recursive_function_test",
        parameters = {"count"},
        expression = "if(count <= 0, 0, claustorephobic_recursive_function_test(count - 1) + 1)"
}
Then put it literally anywhere its value will be used. Congrats, the game should now crash on startup.

I assume this is probably best fixed by just making it error before it's fully parsed, which is what I assume causes the crash.

Re: Recursive noise functions crash without erroring

Posted: Thu Mar 12, 2026 11:45 am
by Rseding91
I'll leave this up to Genhis but generally detecting if something is recursive is far more expensive than just letting it crash and saying "don't do that" to the bug reports. Functionally it's the same - but we don't end up paying the performance cost when it's not recursive.

Re: Recursive noise functions crash without erroring

Posted: Thu Mar 12, 2026 2:05 pm
by Genhis
I agree with Rseding, it doesn't seem worth implementing recursion detection logic.

Re: Recursive noise functions crash without erroring

Posted: Thu Mar 12, 2026 4:04 pm
by braxbro
Genhis wrote: Thu Mar 12, 2026 2:05 pm I agree with Rseding, it doesn't seem worth implementing recursion detection logic.
Fair. People could bury the recursion deep. Wonder if you could catch the crash though & handle it that way.

Either way, should probably be documented?

Re: Recursive noise functions crash without erroring

Posted: Thu Mar 12, 2026 5:26 pm
by Rseding91
I'm not sure if it's really worth documenting. In computing terms: infinite recursion is a programmer bug and can happen virtually anywhere. It's up to the programmer to *just don't do that* since there's no other option. Anywhere a mod developer can write recursive functions (the entirety of runtime modding) can result in infinite recursion and a crash.

Re: Recursive noise functions crash without erroring

Posted: Thu Mar 12, 2026 6:21 pm
by braxbro
Rseding91 wrote: Thu Mar 12, 2026 5:26 pm I'm not sure if it's really worth documenting. In computing terms: infinite recursion is a programmer bug and can happen virtually anywhere. It's up to the programmer to *just don't do that* since there's no other option. Anywhere a mod developer can write recursive functions (the entirety of runtime modding) can result in infinite recursion and a crash.
Yeah, but in this case it was finite recursion causing the crash. Not that the end of data stage probably knows that, but I just did recursive_func(40) and it blew up. It appears to be any recursion at all that does it.