Fluid Permutations

by spiwn

Rotate fluid inputs and outputs of buildings

Utilities
3 years ago
0.16 - 1.1
17.7K

g [Fixed] Crash on loading a save game that has other mods

6 years ago

on_configuration_changed is being fired by other mod first, this case, bobs plates and is event he does a reset_technology_effects.
Since you events havent fired yet and you dont have yet build the Registry, it crashes on load.

237.651 Error AppManagerStates.cpp:1301: Error while running on_configuration_changed: Error while running event fluid_permutations::on_technology_effects_reset (ID 99)
fluid_permutations/control.lua:68: attempt to index global 'unlocks' (a nil value)
stack traceback:
bobplates/control.lua:3: in function <bobplates/control.lua:1>

6 years ago

I will look into it.

6 years ago

While what you described can cause some problems, it does not cause this.
Indeed the "registry" is not built, but the result is that nothing happens, since it is empty.
The error that causes that error message is that the global variable unlocks (as in being in the global scope, not to be confused with global.unlocks) is nil. That is possible only if on_init has not run, nor on_configuration_changed, nor on_load. But as far as I can see on_init or on_load (depending on whether you had the mod in the save already) will run before any other event - or in other words, all mods will load before any events sent to that mod.
So either I am missing something or you have other modifications to the mod.

6 years ago
(updated 6 years ago)

on_init - This is called once when a new save game is created or once when a save file is loaded that previously didn't contain the mod. So, it will never run in this case!

on_load fires when the mod is being loaded after all necessary initializations have run and that means, inits necessary when a config changes.

So, this leaves on_configuration_changed to be the first event to be fired. But, there is no guaranteed order for it to fire. Multiple mods have this event registered and any of them can fire before yours. If one of them resets the technology effects, then the technology effects event will be fired on all mods that have it registered, including yours. All this, before your on_configuration_changed event ever fired!
And, as you can see on the error I posted before, the stacktrace comes from bobs-plates in his own on_configuration_changed event where he calls the technology effect reset...

A very simple fix is checking if unlocks is defined in your togglePermutations, to prevent it to run before you have built your registry. Then, when your own on_configuration_changed runs, it will build the registry and, if you want, to be super safe, force a technology reset in it after the registry was built, to force togglePermutations to run now that the registry is built! After all, configurations changed, so you need to be sure all permutations are correct!

Edit: only change I made on your mod was adding MoreScience-SeaBlockExtension on the optional requesites to guarantee that your mod catch other recipe changes on this mod and now, the verification if unlocks is null so the save could load!

6 years ago

The order of events fired is: first on_init/on_load for all mods (Bob's plates and Fluid permutations). After these two have fired for all mods (Bob's plates and Fluid permutations) other events are processed, but not before. Then on_configuration_changed fires for bob's plates and it calls .reset_technology_effects(), which in turn triggers the on_technology_effects_reset() in fluid permutations. After that has completed, on_configuration_changed in Fluid permutations is triggered. Since on_load is triggered before the on_technology_effects_reset the global variable unlocks is not nil and that error does not happen.
I tried a lot of scenarios in order to reproduce this error and none resulted in this error.

6 years ago

I found the real problem. I will fix it shortly.

6 years ago

I had the impression on_init would not fire, since I was not adding the mod and that on_load would only fire after on_configuration_changed fired, so any new changes to the save could be calculated and the on_load could start with those required configuration changes already processed and go on with is normal live....

In that case, what was the issue? Academical curiosity... :-)

6 years ago
(updated 6 years ago)

on_init will not fire if the mod was already present in the save, like you said above. However in that case on_load will fire. So it is guaranteed that either on_init or on_load will fire - that is what I meant.
So either on_init or on_load will finish for all mods before on_configuration_changed is triggered for any mod. This is guaranteed. The idea is that on_init/on_load is required for the mod to start working and before it can handle any other events.
There are no such guarantees for on_configuration changed.

The problem was that unlocks was added after the initial release, so for existing saves global.unlocks was nil. So on_load fired, but the global variable unlocks was set to nil.

New response