[0.12.x] [kovarex] Weird recipe indexing crash

Bugs that are actually features.
Post Reply
User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

[0.12.x] [kovarex] Weird recipe indexing crash

Post by bobingabout »

Tested on 0.12.12 and after updating to 0.12.16.

https://forums.factorio.com/forum/vie ... 99#p116199
Download that mod pack.

This is a very strange issue that seems to be a specific interaction between my electronics/library mods, and yuoki-engines 1.7.
You'll also need to include some of my other mods to make sure bobelectronics doesn't trigger a crash when it calls "bobmods.lib.remove_technology_recipe("advanced-electronics-2", "electronic-processing-board")"

My library function call does the following:

Code: Select all

function bobmods.lib.replace_item_all_recipes (old, new)
  for i, recipe in pairs(data.raw.recipe) do
    bobmods.lib.replace_recipe_item (recipe.name, old, new)
  end
end

function bobmods.lib.replace_recipe_item (recipe, old, new)
  local doit = false
  local amount = 0
  for i, ingredient in pairs(data.raw.recipe[recipe].ingredients) do
    if ingredient[1] == old then
      doit = true
      amount = ingredient[2] + amount
    end
    if ingredient.name == old then
      doit = true
      amount = ingredient.amount + amount
    end
  end
  if doit then
    bobmods.lib.remove_recipe_item (recipe, old)
    bobmods.lib.add_recipe_item (recipe, {new, amount})
  end
end
The error is on line 4 of the bobmods.lib.replace_recipe_item function, "for i, ingredient in pairs(data.raw.recipe[recipe].ingredients) do".
The issue apears to be that the recipe it is indexing via the recipe name obtained in the bobmods.lib.replace_item_all_recipes function doesn't exist.

I do not understand why, because it is accessing every recipe in order, it was obtained from recipe.name, then passed to the other function.


Also, Can we have some kind of lua function stack trace in the error reporting? you have no idea how long it took me to track down this issue with the limited information that it was line 4 of recipe functions in the library mod... I call that function "over nine thousand" times.

Something like...
Line 4 of library recipe functions
called by line 50(guessed) of library recipe functions
called by line 1 of electronics data-updates.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

kovarex
Factorio Staff
Factorio Staff
Posts: 8078
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: [0.12.x] [kovarex] Weird recipe indexing crash

Post by kovarex »

Hmm, I did take a look, and I believe, that the recipe table is just not set correctly.
If there is a recipe in the recipe table without the name property set, this is exactly what would happen and some mod is probably doing so, I can't really test it, as there are other errors in the script pack even when I comment this part out.

I agree that the debugging possibilities are very limited here, I added task to add the "log" method here.

I'm moving this to not a bug, although this is "probably not a bug".

kovarex
Factorio Staff
Factorio Staff
Posts: 8078
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: [0.12.x] [kovarex] Weird recipe indexing crash

Post by kovarex »

I added the global log method to the interface for 0.12.17.

kovarex
Factorio Staff
Factorio Staff
Posts: 8078
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: [0.12.x] [kovarex] Weird recipe indexing crash

Post by kovarex »

Also (with the help of the log method), I know where the problem is, the method replace_recipe_item, is called like this:

Code: Select all

bobmods.lib.replace_recipe_item("assembling-machine-4", "steel-plate", "aluminium-plate")
But on other place, it is used like this:

Code: Select all

for i, recipe in ipairs(data.raw.recipe) do
  bobmods.lib.replace_recipe_item (recipe.name, old, new)
end
So, sometimes, it gets the recipe table, and sometimes just the name, so the function should probably handle both or something.

P.S. The log can be also used to get the stacktrace this way:

Code: Select all

log(debug.traceback()) -- can be handy while debugging.

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: [0.12.x] [kovarex] Weird recipe indexing crash

Post by bobingabout »

So the error is likely in Youki Engines. I'll try to add some more checks to the function to make sure the data is valid before using it.

Thanks for taking a look, and for the log trace.

So what do I do with the log(debug.traceback()) line? add it to the function that I want to trace?
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

kovarex
Factorio Staff
Factorio Staff
Posts: 8078
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: [0.12.x] [kovarex] Weird recipe indexing crash

Post by kovarex »

bobingabout wrote:So the error is likely in Youki Engines. I'll try to add some more checks to the function to make sure the data is valid before using it.

Thanks for taking a look, and for the log trace.

So what do I do with the log(debug.traceback()) line? add it to the function that I want to trace?
It depends on you, but yes, for example. But it should be used only for debugging.

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: [0.12.x] [kovarex] Weird recipe indexing crash

Post by bobingabout »

kovarex wrote:But it should be used only for debugging.
That's what I was thinking, if it is there all the time, it would fill everyone's logs with every function call.
I'll make a note and give it a try.

Once again, Thanks for the help!
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

Post Reply

Return to “Not a bug”