Page 1 of 1

[2.1.9] Crash on LuaHelpers::write_file

Posted: Thu Jul 02, 2026 5:31 am
by RedRafe
Hello,

game crashes when in control I use LuaHelpers::write_file with optional parameter "for_player=0"

Code: Select all

-- crashes in single player
helpers.write_file('file.json', data, false, 0)

-- does NOT crash in single player
helpers.write_file('file.json', data, false)
Attached is the log of the crash.

Re: [2.1.9] Crash on LuaHelpers::write_file

Posted: Thu Jul 02, 2026 5:47 am
by boskid
I see, write_file's for_player was never implemented to work when control.lua top level is executed because at that stage it is not yet decided who is a local player or if thats a server. Before `helpers` existed, write_file was on `game` which was not available at that stage and it was not possible to do writes yet.

Re: [2.1.9] Crash on LuaHelpers::write_file

Posted: Thu Jul 02, 2026 1:28 pm
by boskid
Thanks for the report. Issue is now fixed for 2.1.10. When trying to use write_file with for_player != 0 from top level, write will be skipped because at that point local player cannot be decided yet. When using for_player == 0, it will not crash.

Re: [2.1.9] Crash on LuaHelpers::write_file

Posted: Thu Jul 02, 2026 1:32 pm
by RedRafe
Thanks, seems reasonable.
Can I also ask for this to be added to the new API docs when released (if not already taken care of).
Ty

Re: [2.1.9] Crash on LuaHelpers::write_file

Posted: Thu Jul 02, 2026 3:59 pm
by Bilka
Docs updated for 2.1.10.