Page 1 of 1

[1.1.34] Crash when attempting to paste lua-script created blueprint with invalid snap-to-grid configuration

Posted: Fri Jun 11, 2021 5:32 pm
by GlassBricks
I'm creating a (yet to be released) mod that involves programmatically creating/pasting blueprints.

In the mod, using lua, I created a blueprint (inside a container inside a custom surface to hold the LuaItemStack), set blueprint_position_relative_to_grid, but did not set blueprint_snap_to_grid. When I tried to place this blueprint (from lua), the game (not the mod) crashed.

Setting blueprint_snap_to_grid to {1,1} avoided the crash.

I would expect the blueprint pasting to fail gracefully or provide a reasonable default behavior, instead of crashing the game.

Re: [1.1.34] Crash when attempting to paste lua-script created blueprint with invalid snap-to-grid configuration

Posted: Thu Jun 17, 2021 1:46 pm
by posila
Hello, thanks for the report.
Can you provide the lua code that causes the crash, please?

Re: [1.1.34] Crash when attempting to paste lua-script created blueprint with invalid snap-to-grid configuration

Posted: Sat Jun 26, 2021 3:41 am
by GlassBricks
Here's a portion of the code that produced the crash:

Code: Select all

-- (in a function)
local blueprint = getBpForLayer() -- creates and returns a LuaItemStack in a script inventory, that is a blueprint
local blueprintedEntities = blueprint.create_blueprint({surface = self.surface, force = "player", area = self.area, include_entities = true, include_modules = true, include_trains = true, include_station_names = true, include_fuel = true})
if isEmpty(blueprintedEntities) then
    return blueprint
end
local someEntity = blueprintedEntities[1]
local blueprintEntity = blueprint.get_blueprint_entities()[1]
-- blueprint.blueprint_snap_to_grid = {1, 1} -- Omitting this line results in crash
blueprint.blueprint_position_relative_to_grid = position:subtract(someEntity.position, blueprintEntity.position) -- util function that subtracts x and y
return blueprint

-- (run later)

blueprint.build_blueprint({surface = self.surface, force = "player", position = {0, 0}, skip_fog_of_war = false, force_build = forceBuild})