Page 1 of 1

[Modding] Setting string.icon to non-nil value crashes the game.

Posted: Mon Jun 01, 2026 3:30 am
by everything-narrative
As demonstrated here:

https://mods.factorio.com/mod/OnTheImpo ... gYourTypes

On line 62 in base/data-updates.lua there is a check for whether something is a filename or an IconData whcih relies on table lookups in strings going through the metatable into the global string table, and so that check works only so long as string.icon is not set.

Proposed solution (included in the mod files) is to just check the types the proper way.

Re: [Modding] Setting string.icon to non-nil value crashes the game.

Posted: Mon Jun 01, 2026 8:47 am
by Klonan
everything-narrative wrote: Mon Jun 01, 2026 3:30 am Proposed solution (included in the mod files) is to just check the types the proper way.
Thanks for the report, but I don't think we really want to go down this rabbit hole

Crafting a specific Lua table/value with a sneaky metatable for the sole purpose of breaking this specific function,
Well we have hundreds of similar functions and we don't want to worry about it

Its a crash for only the mod author who goes out of their way to use a non-compliant data type with this function,
Furthermore, It might not be clear, but it isn't crashing? just throwing a script error, which is a already handling the result correct enough

Or if it is crashing can you provide a log file with the crash log?

Re: [Modding] Setting string.icon to non-nil value crashes the game.

Posted: Mon Jun 01, 2026 11:37 am
by Bilka
It is just a file not found error in minimal mode, same as when you provide an icon path for a non-existent file to the generate_barrel_icons method, not a game crash.

We generally don't care about script errors caused by intentionally feeding junk to utility functions or modifying Lua state in ways that break basic assumptions of Lua, e.g. setting math = nil. That is classed under "stop hitting yourself".

Despite that, I changed the function for 2.1 to check the type properly, since it is trivial and I was already looking at it. Note that it is not intended to accept IconData, but instead an item prototype with a simple icon definition.

Re: [Modding] Setting string.icon to non-nil value crashes the game.

Posted: Mon Jun 01, 2026 12:27 pm
by everything-narrative
Thank you. I'll deprecate the mod once the issue is resolved. Glad to hear it is being addressed, always a big fan of improving code quality, readability, and idiomatic-ness(?)

Happy coding!

(Also I am currently on garden leave and have a lot of time on my hands, so if it'd be useful, I'd love to to go over your lua codebase with a fine tooth comb and write rigorous unit tests that can ensure behavioral compliance in refactoring. It would look good on my CV. :lol: )