raiguard / RecipeBook

Recipe Book for Factorio.
MIT License
20 stars 9 forks source link

Adding a recipe to a savegame gives error #86

Closed Myricaulus closed 2 years ago

Myricaulus commented 2 years ago

Describe the Bug

After adding a recipe to a mod and loading a savegame which was working before it fails to load with exception: The mod Recipe Book (3.2.1) caused a non-recoverable error. Please report this error to the mod author.

Error while running event RecipeBook::on_load() RecipeBook/scripts/processors/technology.lua:37: attempt to index local 'recipe_data' (a nil value) stack traceback: RecipeBook/scripts/processors/technology.lua:37: in function 'technology_proc' RecipeBook/scripts/recipe-book.lua:65: in function 'build' RecipeBook/control.lua:124: in function <RecipeBook/control.lua:117>

This is the recipe i added to "jr-metals_0.1.3": { type = "recipe", name = "copper-cable2", enabled = false, category = "crafting-with-fluid", energy_required = 10, ingredients = { {type="fluid", name="molten-copper", amount=15} }, results = { {type = "item", name = "copper-cable", amount = 30} }, }, After removing the recipe it again loaded normally. After removing RecipeBook the game also loaded including the recipe., with FNEI showing it normally.

To Reproduce

Steps to reproduce the behavior:

  1. Add this recipe to jr-metals_0.1.3 & extend the technology.lua with it
  2. Load attached Savegame
  3. See error

Be certain to reproduce the issue on the same save file that you upload.

Save file & Username

SpaceEx.zip Username Myricaulus

Log file

factorio-previous.log . Good Luck :-)

raiguard commented 2 years ago

This is a known issue. Recipe Book keeps all of the actual data outside of global to speed up save times, and must re-generate it during on_load. I have special checks in place so that it won't run the logic if mod configuration is changing. But there is no good way for me to handle if prototype values change without mod configuration changing. Fixing this would be a monumental effort, and is simply not worth it, because it only happens when you change a mod's contents without changing its version number.

Myricaulus commented 2 years ago

So just increase the version number, then the recipe book would work? Maybe add this info to any documentation, so others at least will not fall into this trap.

raiguard commented 2 years ago

That is correct. I'll add a note to the mod portal page and to the readme here on GitHub.

MarximusMaximus commented 2 years ago

Would it be possible to add a check before where this usage occurs and just rebuild the cache at that time? I'm hitting this a lot while editing a mod locally before actually bumping the version for a release.

raiguard commented 2 years ago

I actually found a way to fix this and implemented it for the next version. If you want, you can splice the code in to your copy of the mod (or just clone the repo).

Replace global_data.check_should_load() in scripts/global-data.lua with this:

function global_data.check_should_load()
  local sync_data = global.sync_data or { active_mods = {}, settings = {} }

  if
    global.prototypes
    and table.deep_compare(sync_data.active_mods, script.active_mods)
    and table.deep_compare(sync_data.settings, settings.startup)
  then
    for _, prototypes in pairs(global.prototypes) do
      for _, prototype in pairs(prototypes) do
        if not prototype.valid then
          return false
        end
      end
    end
    return true
  end

  return false
end
MarximusMaximus commented 2 years ago

Neat! Thanks!