Page 1 of 1

[2.1.17] Crash: `LuaSimulation.control_press` in a main menu simulation

Posted: Sun Sep 06, 2026 8:22 pm
by sparr
Version: 2.1.17 (build 87315, linux64, steam, space-age)
OS: Linux (EndeavourOS rolling), X11

What happens

Calling LuaSimulation.control_press from a mod script running inside a main menu simulation aborts the game. An empty Optional is dereferenced in luaControlDown.

Code: Select all

Error Optional.hpp:63: *this was not true
Error CrashHandler.cpp:616: Received 6

src/Util/Container/Optional.hpp (63): operator*
src/Script/LuaSimulation.cpp (446): luaControlDown
_ZN13LuaSimulation15luaControlPressEP9lua_State
src/Script/LuaBinder.hpp (424): callWrapperOnObject
Crashes at map tick 0, 100% reproducible.

Steps to reproduce

Create a mod named simcrash with the three files below, then launch Factorio normally (no --load-game). The main menu simulation starts on its own and the game aborts within a second.

info.json

Code: Select all

{ "name": "simcrash", "version": "0.0.1", "title": "LuaSimulation.control_press crash", "author": "repro", "factorio_version": "2.1", "dependencies": ["base"] }
data.lua

Code: Select all

data.raw["utility-constants"]["default"].main_menu_simulations = {
  simcrash = { checkboard = true, length = 100000, mods = { "simcrash" } },
}
control.lua

Code: Select all

script.on_nth_tick(60, function()
  local sim = game.simulation
  if not sim then return end
  sim.camera_player = sim.create_test_player { name = "tester" }
  sim.control_press { control = "undo", notify = false }   -- crashes here
end)
Notes
  • Not specific to undo. control_press { control = "open-character-gui" } aborts with the same stack.
  • The camera_player assignment is what gets you to the crash. Without it, control_press fails cleanly with "Input source doesn't have a player.", so there is a guard on that path but seemingly not on this one. Setting camera_player appears to satisfy the check while leaving whatever luaControlDown dereferences unset.
  • create_test_player and the camera_player assignment both succeed. Only the press aborts.
  • control_down is presumably affected too, since the stack shows luaControlPress calling luaControlDown.
What I was trying to do

Driving a player control from an automated test harness, specifically applying an undo so a test can assert what ctrl+z actually does. There is no runtime API that applies an undo: LuaUndoRedoStack can read, tag and remove entries but not apply one. control_press inside a simulation looked like the intended route, and create_test_player suggests simulations are meant for exactly this.

AI Disclosure

This crash was identified and documented by Claude Opus 5 while I was using it to develop a test harness for another mod. It also authored most of this bug report.

Re: [2.1.17] Crash: `LuaSimulation.control_press` in a main menu simulation

Posted: Sun Sep 06, 2026 8:43 pm
by sparr
Based on Discord conversation and further testing, setting `camera_player_cursor_position` in advance avoids this crash by filling in the "Optional" cursor position.

Re: [2.1.17] Crash: `LuaSimulation.control_press` in a main menu simulation

Posted: Wed Sep 09, 2026 2:30 pm
by Rseding91
Thanks for the report. This is now fixed for the next release.