[0.18.10][Modding] LuaSurface.find_non_colliding_position() Infinite Loop 0 Radius

Bugs that are actually features.
User avatar
DedlySpyder
Filter Inserter
Filter Inserter
Posts: 253
Joined: Fri Jun 20, 2014 11:42 am
Contact:

[0.18.10][Modding] LuaSurface.find_non_colliding_position() Infinite Loop 0 Radius

Post 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
User avatar
DedlySpyder
Filter Inserter
Filter Inserter
Posts: 253
Joined: Fri Jun 20, 2014 11:42 am
Contact:

Re: [0.18.10][Modding] LuaSurface.find_non_colliding_position() Infinite Loop 0 Radius

Post 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.
Rseding91
Factorio Staff
Factorio Staff
Posts: 14265
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [0.18.10][Modding] LuaSurface.find_non_colliding_position() Infinite Loop 0 Radius

Post 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.
If you want to get ahold of me I'm almost always on Discord.
User avatar
DedlySpyder
Filter Inserter
Filter Inserter
Posts: 253
Joined: Fri Jun 20, 2014 11:42 am
Contact:

Re: [0.18.10][Modding] LuaSurface.find_non_colliding_position() Infinite Loop 0 Radius

Post by DedlySpyder »

OK, maybe a warning in the docs then? I spent a good chunk of time thinking my code had an infinite loop.
Post Reply

Return to “Not a bug”