Nuclear Scorch Decay


Continuously removes nuclear scorch marks by slowly changing the scorched tiles to match their surroundings.

Tweaks
10 days ago
2.0 - 2.1
1.05K
Environment

b Random crash, possibly incompatibility

15 days ago

This might be an incompatibility with subterranio, as I have recently installed that mod. Still digging through control.lua to figure out how chunk selection works.

Error while running event nuclear-scorch-decay::on_nth_tick(10)
nuclear-scorch-decay/control.lua:85: attempt to index local 'chunk' (a nil value)
stack traceback:
nuclear-scorch-decay/control.lua:85: in function 'get_sub_chunks'
nuclear-scorch-decay/control.lua:104: in function <nuclear-scorch-decay/control.lua:99>

10 days ago

Hit the same crash without Subterranio installed, so it's not that mod specifically.

What's happening:

With chunk selection set to "random", get_chunk() picks a random surface and checks it has chunks using surface.get_chunks().
It then calls surface.get_random_chunk() to pick one. Problem: that function only considers generated chunks, and some surfaces (space platforms in my case, probably Subterranio's underground layers in yours) have chunks in the iterator but none counted as generated.
On those surfaces get_random_chunk() returns nil, the nil gets passed into get_sub_chunks(), and indexing chunk.x crashes at control.lua:85.
So any mod that adds these kinds of surfaces can trigger it — it's a matter of time until the random pick lands on one.

How to patch it (unzip the mod, edit control.lua, rezip — or wait for the author):

In get_chunk(), right after the if/elseif chunk-selection block ends (just before the storage.map_marker lines, around line 72), add:
-- get_random_chunk() returns nil on surfaces with no generated chunks
-- (e.g. space platforms); skip this cycle instead of crashing
if chunk == nil then
return nil
end
In the on_nth_tick handler (around line 102), make the caller handle that nil:
if (#storage.nuclear_tiles==0 and storage.sub_chunks==nil) then
local chunk = get_chunk()
if chunk == nil then return end -- <<< add this line
storage.chunk = chunk
storage.sub_chunks = get_sub_chunks(chunk.chunk, chunk_subdivisions)
(Optional but recommended) In the two later branches that start with local surface = storage.chunk.surface, add a guard right after that line — a stored surface can be deleted mid-scan (e.g. a destroyed space platform) and crashes the same way on the next cycle:
if not surface.valid then
storage.chunk = nil
storage.sub_chunks = nil
storage.nuclear_tiles = {}
return
end
The mod just skips that cycle and picks a fresh chunk next time — no behavior change otherwise. Been running this patched for a while with no recurrence.

10 days ago
(updated 10 days ago)

Very sorry, I got the notification for this and then entirely forgot about it - thank you for looking into the problem and finding a solution while I was busy being a doofus.

I am working on an overhaul for this and two other closely related mods that should make it more reliable, more performant, and a hell of a lot less hacky, but that could be in the works for a while yet.

I'll push a hotfix version with your fix included to tide things over until then. Thanks again.

Edit: After looking at the function again for the first time in probably years I found a simpler fix - rerolling the surface and chunk inside a loop until chunk isn't nil (thanks to the "p" in "prng" it should never need to reroll more than a couple of times). Still, thank you for trying to find a solution regardless.

New response