[2.1.17] unbounded spill_item_stack freezes game

Bugs that are actually features.
sparr
Smart Inserter
Smart Inserter
Posts: 1572
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

[2.1.17] unbounded spill_item_stack freezes game

Post by sparr »

What happens

LuaSurface::spill_item_stack does not return when no max_radius is given and there is no position anywhere in the surface's generated chunks that will hold the item. The game stops responding. It does not raise an error, it does not log anything, and it does not come back on its own; killing the process is the only way out.

Steps to reproduce

From a single player game. Each of these is one line -- paste it into the console and press enter. /c disables achievements for the save, which is what a reproduction costs.

1. Make a surface of its own and drown every generated chunk of it, so there is nowhere on that surface that will hold an item on the ground (but this also happens on natural space platforms):

Code: Select all

/c local s = game.create_surface("drowned") s.request_to_generate_chunks({0,0}, 2) s.force_generate_chunk_requests() for c in s.get_chunks() do local t = {} for x = c.area.left_top.x, c.area.right_bottom.x-1 do for y = c.area.left_top.y, c.area.right_bottom.y-1 do t[#t+1] = {name="deepwater", position={x,y}} end end s.set_tiles(t) end game.print("surface "..s.name..", dry land left: "..#s.find_tiles_filtered{area={{-512,-512},{512,512}}, collision_mask="player", invert=true})
It prints dry land left: 0.

2. The control. The same spill with a max_radius:

Code: Select all

/c game.print("bounded call returned, made "..#game.surfaces["drowned"].spill_item_stack{position={0.5,0.5}, stack={name="iron-plate", count=1}, max_radius=8})
It prints bounded call returned, made 1, immediately.

3. The same spill again with max_radius left out:

Code: Select all

/c game.print("unbounded call returned, made "..#game.surfaces["drowned"].spill_item_stack{position={0.5,0.5}, stack={name="iron-plate", count=1}})
Nothing is printed and the game stops responding.

Expected: the third command returns when it runs out of places to search, even if it failed to place.
Rseding91
Factorio Staff
Factorio Staff
Posts: 17574
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [2.1.17] unbounded spill_item_stack freezes game

Post by Rseding91 »

Thanks for the report. The logic will eventually return but an unbounded search takes a *long* time to finish as it iterates all possible locations that the max radius covers.

There’s a reason that max radius exists since trying to check literally every possible position that can be generated on a max sized 1mx1m map is incredibly slow.
If you want to get ahold of me I'm almost always on Discord.
sparr
Smart Inserter
Smart Inserter
Posts: 1572
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: [2.1.17] unbounded spill_item_stack freezes game

Post by sparr »

Why can it not return "early" once it has searched past every generated chunk?
Rseding91
Factorio Staff
Factorio Staff
Posts: 17574
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [2.1.17] unbounded spill_item_stack freezes game

Post by Rseding91 »

The logic expects that chunks are generated and that there is a valid location to put the spilled items. As such, it doesn’t do extra checking for each position to check if it has gone over all possible generated chunks (which could be thousands to tens of thousands or more).

In simpler terms: performance matters and checking if it has iterated out past all generated chunks adds a lot of overhead for the expected success case.
If you want to get ahold of me I'm almost always on Discord.
Post Reply

Return to “Not a bug”