Page 1 of 1
[0.18.10][Modding] LuaSurface.find_non_colliding_position() Infinite Loop 0 Radius
Posted: Fri Mar 06, 2020 3:05 am
by DedlySpyder
LuaSurface.find_non_colliding_position() with a 0 radius (which says it just searches intimately large) actually just loops infinitely. I made a small 10x10 empty surface and any time I ran it with 0 radius the game just hung and rapidly increased in memory.
Code: Select all
function breakFactorio()
local surface = game.create_surface("test", {width = 10, height = 10})
surface.find_non_colliding_position("wooden-chest", {0,0}, 0, 1, true)
log("DONE")
end
Re: [0.18.10][Modding] LuaSurface.find_non_colliding_position() Infinite Loop 0 Radius
Posted: Fri Mar 06, 2020 3:24 am
by DedlySpyder
After some more poking around at this, it seems that the chunks aren't generated yet (this confused me, because teleporting the character still works, I assume because it forces the generate). By calling the below I was able to use infinite radius.
Code: Select all
surface.request_to_generate_chunks({0,0}, 1)
surface.force_generate_chunk_requests()
While that is fine, the expectation would be that the game should either error out and let me know that no chunks are generated or return nil.
Re: [0.18.10][Modding] LuaSurface.find_non_colliding_position() Infinite Loop 0 Radius
Posted: Fri Mar 06, 2020 11:57 am
by Rseding91
Thanks for the report. That's unfortunately just how that has to work if you want a guarantee that it never returns until it finds a valid location. Otherwise it would always have to be nil checked for everyone's use-case.
Re: [0.18.10][Modding] LuaSurface.find_non_colliding_position() Infinite Loop 0 Radius
Posted: Fri Mar 06, 2020 12:07 pm
by DedlySpyder
OK, maybe a warning in the docs then? I spent a good chunk of time thinking my code had an infinite loop.