[Genhis] [1.1.64] Crash when player undoes tile deconstruction orders assigned to different force (via script)

This subforum contains all the issues which we already resolved.
azaghal
Inserter
Inserter
Posts: 36
Joined: Sat Jun 27, 2020 11:13 am
Contact:

[Genhis] [1.1.64] Crash when player undoes tile deconstruction orders assigned to different force (via script)

Post by azaghal »

Game crashes when player attempts to undo tile deconstruction orders which has been created for a non-player force, but assigned to the player using a deconstruction planner (via script).

Reproduction steps:
  1. Set-up and load a minimal mod with the following control.lua script:

    Code: Select all

    function reproduce_bug(command)
        local player = game.players[command.player_index]
    
        if not global.inventory then
            global.inventory = global.inventory or game.create_inventory(1)
            global.inventory.insert({ name = "deconstruction-planner" })
        end
    
        if not global.friendly then
            global.friendly = game.create_force("friendly")
            player.force.set_friend(global.friendly, true)
            global.friendly.set_friend(player.force, true)
        end
    
        deconstruction_planner = global.inventory[1]
        deconstruction_planner.tile_selection_mode = defines.deconstruction_item.tile_selection_mode.only
    
        local tiles = {}
        for x = -2, 2 do
            for y = -2, 2 do
                table.insert(tiles, {name = "stone-path", position = {x, y}})
            end
        end
    
        player.surface.set_tiles(tiles)
    
        deconstruction_planner.deconstruct_area {
            surface = player.surface,
            force = global.friendly,
            area = { {-2, -2}, {2, 2} },
            skip_fog_of_war = false,
            by_player = player
        }
    end
    
    
    commands.add_command("other_force_undo_crash", nil, reproduce_bug)
    
  2. Start a new game with only the crash reproduction mod and default map settings.
  3. Run the console command (this will spawn some tiles, and order their deconstruction for a force to which the player does not belong, but still mark it as initiated by the player) :

    Code: Select all

    /other_force_undo_crash
    
  4. Trigger undo action (CTRL-Z).

    Expected results:
    • During step (4), nothing happens.
    Actual results:
    • During step (4), the game crashes.
    Additional notes:
    • Log file has been attached. Take note that I use a management script in order to run multiple Factorio instances in their dedicated directories (therefore the weird paths).
    • This is fairly anomalous thing for a script to do, but I happened to be working on some code for the Construction Planner Continued mod which does some weird things with multiple forces and deconstruction planners when I ended-up triggering this (it was error in my mod code that this happened in the first place).
    • Not sure what the real expected behaviour would be in this case since players normally do not deconstruct tiles in the name of other entities.
    • I have not seen any issues being caused for entities, I think it affects only tiles.
    • Crash was reproduced with versions 1.1.61 and 1.1.64.
Attachments
factorio-current.log
Factorio log with crash stack trace.
(7.34 KiB) Downloaded 106 times
Genhis
Factorio Staff
Factorio Staff
Posts: 681
Joined: Wed Dec 24, 2014 8:19 am
Contact:

Re: [Genhis] [1.1.64] Crash when player undoes tile deconstruction orders assigned to different force (via script)

Post by Genhis »

Thanks for the report. Calling deconstruct_area() with mismatched force will not be allowed in the next release.
azaghal
Inserter
Inserter
Posts: 36
Joined: Sat Jun 27, 2020 11:13 am
Contact:

Re: [Genhis] [1.1.64] Crash when player undoes tile deconstruction orders assigned to different force (via script)

Post by azaghal »

Yikes, I am kinda glad the fix was made, but I kinda was depending on being able to do that in the Construction Planner (Continued) mod in order to try to handle undo history :)
Post Reply

Return to “Resolved Problems and Bugs”