raiguard / EditorExtensions

Extends the Factorio map editor with new features, testing tools, and other utilities to aid with sandbox play and scenario creation.
https://mods.factorio.com/mod/EditorExtensions
Other
26 stars 6 forks source link

Crash when exiting editor mode with an item in cursor and not enough inventory space in player inventory #95

Closed jpsenior closed 2 years ago

jpsenior commented 2 years ago

Describe the Bug

In editor mode, one can create an item freely from the crafting window. The player inventory size is less than the available inventory size in editor mode. If the 'player' inventory capacity is full, and an item is on the cursor when exiting editor mode, a crash happens.

To Reproduce

Steps to reproduce the behavior:

  1. Start a new fresh game.

  2. Enter Editor mode.

  3. Fill every possible player-inventory slot full of something - it doesn't matter what. The editor inventory is larger than the player inventory. image

  4. Craft an item and hold it in the cursor. The game can't push this item to the player inventory because it is full. image

  5. Exit editor mode. Crash happens immediately image

Error while running event EditorExtensions::on_player_toggled_map_editor (ID 120)
Slot index out of inventory bounds.
stack traceback:
        [C]: in function '__newindex'
        __EditorExtensions__/scripts/inventory.lua:80: in function 'get_from_sync_inventories'
        __EditorExtensions__/control.lua:604: in function <__EditorExtensions__/control.lua:568>
        [C]: in function 'toggle_map_editor'
        __EditorExtensions__/control.lua:164: in function <__EditorExtensions__/control.lua:158>
stack traceback:
        [C]: in function 'toggle_map_editor'
        __EditorExtensions__/control.lua:164: in function <__EditorExtensions__/control.lua:158>"
93887.582 Info ServerMultiplayerManager.cpp:797: updateTick(64601731) changing state from(InGame) to(Failed)

Be certain to reproduce the issue on the same save file that you upload.

Save file & Username

I don't think a save file is important for this, it can be reproduced instantly on a fresh world.

Log file

jpsenior commented 2 years ago

I attempted to just comment out the corresponding code from the lua file...

          --if hand_location and hand_location then
          --  player.hand_location = { inventory = inventory_def, slot = hand_location }
          --end

The crash is avoided -- and I don't lose the item either. Maybe it's not necessary to swap handheld items?

raiguard commented 2 years ago

Thank you for the very detailed bug report!