[1.1.80] asking to generate chunks while forcing chunk generation fails

Bugs that are actually features.
Post Reply
mrvn
Smart Inserter
Smart Inserter
Posts: 5710
Joined: Mon Sep 05, 2016 9:10 am
Contact:

[1.1.80] asking to generate chunks while forcing chunk generation fails

Post by mrvn »

I'm generating a fractal map in the on_chunk_generated event but I don't want to loose resources when I replace land with water. I want to move ore patches and for that I need the whole ore patch generated. So every time I hit a chunk with resources on it I check and generate all chunks around it using

Code: Select all

      surface.request_to_generate_chunks({x0, y0}, 32)
      surface.force_generate_chunk_requests()
The forcing causes more chunks to be generated and that adds more chunks to the queue and forces the generation again. This run for quite a while until it didn't:

81.003 Error MapGenerationManager.cpp:252: MapGenerationHelper::applyTaskResult(..., force) didn't finish all requests.
81.003 Error CrashHandler.cpp:637: Received 6
Logger::writeStacktrace skipped.
81.003 Error CrashHandler.cpp:191: Map tick at moment of crash: 2313
Attachments
factorio-current.log
radius=32
(686.43 KiB) Downloaded 34 times
Last edited by mrvn on Sun Apr 02, 2023 9:28 pm, edited 1 time in total.

lyvgbfh
Fast Inserter
Fast Inserter
Posts: 165
Joined: Fri Jul 10, 2020 6:48 pm
Contact:

Re: [1.1.80] asking to generate chunks while forcing chunk generation fails

Post by lyvgbfh »

Isn't this causing infinite recursion? Assuming one chunk in 9 has resources, won't your code just continue forever?

Rseding91
Factorio Staff
Factorio Staff
Posts: 13220
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [1.1.80] asking to generate chunks while forcing chunk generation fails

Post by Rseding91 »

Thanks for the report however this is expected. You can not queue more chunks to generate during the chunk generated event because it leads to potential infinite recursion.
If you want to get ahold of me I'm almost always on Discord.

mrvn
Smart Inserter
Smart Inserter
Posts: 5710
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: [1.1.80] asking to generate chunks while forcing chunk generation fails

Post by mrvn »

lyvgbfh wrote:
Sun Apr 02, 2023 8:22 pm
Isn't this causing infinite recursion? Assuming one chunk in 9 has resources, won't your code just continue forever?
Assuming resources are somewhat separated this will recourse over all chunks till it has a border of chunks without resources.

mrvn
Smart Inserter
Smart Inserter
Posts: 5710
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: [1.1.80] asking to generate chunks while forcing chunk generation fails

Post by mrvn »

Rseding91 wrote:
Sun Apr 02, 2023 10:37 pm
Thanks for the report however this is expected. You can not queue more chunks to generate during the chunk generated event because it leads to potential infinite recursion.
Then what is the solution for this problem?

Note that I only need the chunks to be generated to see if there are resources on them. I don't need the on_chunk_generated to have been run for them.

I tried writing out the chunks into a variable and then generating them in in_tick(). But in on_tick() the surface.force_generate_chunk_requests() somehow doesn't block and generate the chunks but simply returns.

mrvn
Smart Inserter
Smart Inserter
Posts: 5710
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: [1.1.80] asking to generate chunks while forcing chunk generation fails

Post by mrvn »

mrvn wrote:
Sun Apr 02, 2023 10:47 pm
I tried writing out the chunks into a variable and then generating them in in_tick(). But in on_tick() the surface.force_generate_chunk_requests() somehow doesn't block and generate the chunks but simply returns.
Never mind that. I confused myself because

surface.request_to_generate_chunks(position, radius) takes a MapPosition and a number of chunks

surface.is_chunk_generated(position) takes ChunkPosition

If you use the same position in both calls then that won't work. The first function really shouldn't take a MapPosition when it takes the radius in chunks.

Post Reply

Return to “Not a bug”