[1.1.104] LuaForce.chart() area safety check incorrect

This subforum contains all the issues which we already resolved.
commanderguy3001
Burner Inserter
Burner Inserter
Posts: 9
Joined: Sun Jul 30, 2023 7:32 am
Contact:

[1.1.104] LuaForce.chart() area safety check incorrect

Post by commanderguy3001 »

When trying to use the LuaForce.chart() API call with a very large high aspect ratio area (for example, 900000x1 tiles), the game fails with the message:

Code: Select all

Cannot execute command. Error: The given area is too large. A 900096x900096 area would require over 6413 gigabytes of RAM. If you really want to chart that area do it in smaller batches.
There are two weird things about this:
  • the size of the area reported by the game is more than one chunk longer than the area requested, more specifically, there is a discrepancy of 96 tiles.
  • the area that the game reports is a square, even though the chart command was very much non-square. this leads to the game calculating a ram usage amount that is FAR from what it should be.
Doing a bit of reverse maths experimentation, the game seems to calculate the amount of ram using this equation (or something similar to this):

Code: Select all

min_ram_usage = math.ceil(area_size_x/32) * math.ceil(area_size_y/32) * ( 512 + 32*32*8 )
If we follow this math, the expected amount of ram for a 900000x1 tile area should be:

Code: Select all

min_ram_usage = ceil(900096/32)*ceil(1/32)*8704 = ~223MiB
So the behavior that I would expect is that the game would just fulfill the request, since that amount of ram should easily fit on basically every system.

To locally reproduce this issue:
  • create a new savefile with all default settings
  • run

    Code: Select all

    /c game.player.force.chart(game.player.surface,{{0,0},{900000,1}})
    in the chat. you might have to execute this twice.
P.S: if my assumption of the calculation is correct, the localisation for that error message should say "gibibytes" instead of "gigabytes" since the game divides by 1024 repeatedly, not 1000 :P
Rseding91
Factorio Staff
Factorio Staff
Posts: 14269
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [1.1.104] LuaForce.chart() area safety check incorrect

Post by Rseding91 »

Looking at the logic, it seems the documentation is incorrect and the error is correct. The logic takes the area, centers it on 0,0 and then takes the maximum of the width or height and converts it into a square before charting that area.

I have no idea why it works like that but at this point I'm going to leave it for 1.1 and change it to actually chart the area for 2.0.

However, there are 2 things to note:

* The area to be charted is always full chunks so a 900000x1 area will get rounded up to 900000x32
* The error message specifically uses the term gigabytes because that's the one that the vast majority of people in the world understand. If it used the term "gibibytes" we would get bug reports about spelling far more than we do about which word is used.
If you want to get ahold of me I'm almost always on Discord.
Post Reply

Return to “Resolved Problems and Bugs”