Crash when used with New Game+, looking for cause
Closed this issue · 3 comments
I got a bug report for my mod crashing with yours: https://mods.factorio.com/mods/Bilka/NewGamePlus/discussion/20497
I'm unsure where the issue is. I call on_entity_died on every entity that I destroy on nauvis, and simply delete any other surfaces. I however do not delete your factory surfaces. Could it be possible that I delete a surface that one of your entities is placed on, but your mod still tries to do something with it, although the entire.. entity compound of your factories no longer exists on that surface? If that is the case, it would be nice if you could perhaps check if the surface that the factory was placed on still exists. If you can't do that I might have to call on_entity_died on every entity on every surface I delete, which would be rather performance intensive.
Can do. To fix that particular error message, it's enough to add a simple check added to control.lua#L1022.
There might be other crashes though.
Since you check factory.built anyways in that line, would it perhaps be possible to:
- Subscribe to on_pre_surface_deleted:
- Check if any of the factories are on that deleted surface, and if yes, call cleanup_factory_exterior on them
Since the event is relatively rare, the expense of looping through global.factories shouldn't be a concern.
I only skimmed through your code, but I think this should prevent most issues.
Alright, I'll do that.