Closed TobTobXX closed 12 months ago
If you give me a week of time, I'll probably also come up with a PR to fix it. I'd love to try my hand at it, as I'm just getting started in mod dev.
Thanks for the offer, but fortunately this is a pretty simple fix.
I tried to find the error, but I just don't get it.
Something very weird is happening, that we land in the event handler for the infinity loader, not the infinity accumulator. Also the error claims that the LuaEntity is invalid, but I just can't see where it was invalidated, considering I copied the settings after I switched it to buffer mode.
Please, go ahead and fix it. But link the commit here, I'm very interested in what was wrong. Anyway, I learned a lot.
This happened because I'm using the event_handler library, which lets you specify multiple handlers to be run for a given event. The entity was invalidated when the handler in infinity-accumulator.lua
ran, so the handler in infinity-loader.lua
crashed because I forgot to add the validity check. event_handler
does not abort when something is invalid because always checking would hurt performance, and it's easy to do on the mod's side.
Ah, I see. I somehow assumed event handlers would be registered on an entity/surface/whatever, but events are global and all handlers for on_settings_pasted
will receive the event.
If I may ask, why are you using event_handler.add_libraries()
instead of game.on_event()
? Is there a difference between these two interfaces, or is it just because it makes the code look how you want?
event_handler
is a wrapper over script.on_event
. script.on_event
only supports one handler per event, so event_library
exists to allow multiple handlers to exist. It just calls script.on_event
and gives it a function that loops over all the functions you specified and calls them.
Description
This is the error that pops up:
Factorio version: 1.1.87 Editor extension version: 2.2.0 flib version: 0.12.9
Reproduction