[0.16.51] Crash when hovering mouse above a recipe

This subforum contains all the issues which we already resolved.
pieppiep
Fast Inserter
Fast Inserter
Posts: 170
Joined: Mon Mar 14, 2016 8:52 am
Contact:

[0.16.51] Crash when hovering mouse above a recipe

Post by pieppiep »

I'm running the linux steam version 0.16.51 and made a little mod with just a data-final-fixes.lua

Code: Select all

local resource_list = {}

for _, resource in pairs(data.raw.resource) do
    if resource.minable.results ~= nil then
        for _, results in pairs(resource.minable.results) do
            if results.type == "item" then
                resource_list[#resource_list + 1] = { results.name, 1 }
            end
        end
    elseif resource.minable.result ~= nil then
        resource_list[#resource_list + 1] = { resource.minable.result, 1 }
    end
end

for _, resource in ipairs(resource_list) do
    data:extend({
        {
            type = "recipe",
            name = "transmute-" .. resource[1],
            subgroup = "raw-resource",
            ingredients = resource_list,
            results = {{ resource[1], #resource_list }}
        }
    })
end
What it does is make a list of all minable ore types and make for each a new recipe to create it with ingredients 1 of each ore type and result the same amount of types but all of the choosen ore type.
With just the basegame and this mod everything works as intended.
But when I add a full angels, bobs, madclown I have 30+ ore types and the game crashes (one core full cpu load) when I hover above the recipe with my mouse.
Loewchen
Global Moderator
Global Moderator
Posts: 9195
Joined: Wed Jan 07, 2015 5:53 pm
Contact:

Re: [0.16.51] Crash when hovering mouse above a recipe

Post by Loewchen »

Post the log please.
pieppiep
Fast Inserter
Fast Inserter
Posts: 170
Joined: Mon Mar 14, 2016 8:52 am
Contact:

Re: [0.16.51] Crash when hovering mouse above a recipe

Post by pieppiep »

Here is the log, but it doesn't contain anything usefull for as far I can see.
The last line in the log is saving finished and after saving I've crashed the game.
So I've added my little testing mod and a savegame with it.
If you load this savegame and don't synchronize the mods the game won't crash, if you let the game load and activate the mods it will crash when your hover the recipe.
Attachments
transmuter_save.zip
(3.12 MiB) Downloaded 109 times
transmuter_0.0.0.zip
(877 Bytes) Downloaded 103 times
factorio-current.log
(11.04 KiB) Downloaded 117 times
Loewchen
Global Moderator
Global Moderator
Posts: 9195
Joined: Wed Jan 07, 2015 5:53 pm
Contact:

Re: [0.16.51] Crash when hovering mouse above a recipe

Post by Loewchen »

So the game does not actually crash, it is just busy until you kill the process?
pieppiep
Fast Inserter
Fast Inserter
Posts: 170
Joined: Mon Mar 14, 2016 8:52 am
Contact:

Re: [0.16.51] Crash when hovering mouse above a recipe

Post by pieppiep »

Yeah, I call a hang a crash, there's no exception or something like it.
I can still alt-tab away and back, but alt-f4 or right click and close doesn't do anything.

/edit
pkill factorio doesn't kill the process, pkill -9 factorio does kill it.
Rseding91
Factorio Staff
Factorio Staff
Posts: 14280
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [0.16.51] Crash when hovering mouse above a recipe

Post by Rseding91 »

Thanks for the report. It's technically not crashed - it's just taking that long to calculate the total raw ingredients for the recipe. The reason being: every one of the plates has a recipe to make it from the ore and each ore has a recipe to make it from every other ore.

So in your example there are 39 different ores.

When the tooltip goes to make the total-raw for that recipe it checks "what recipe makes the thing I need" and sees: there's a recipe that takes 39 different ores and produces my required item.

For each of those 39 different ingredients in the recipe it checks: is there a recipe that makes this item (excluding any recipes I've already used to make the item I'm checking).

So: Magic-Plate takes (Ore 1 ... 39) -> Ore 1 takes (transmute 1 ... 38) -> transmute 1 takes (Ore 2 ... 39) -> Ore 2 takes (transmute 1 ... 39) -> transmute 1 can't be used because it's already in this lookup chain (transmute 2 ... 39) -> transmute 2 takes (Ore 1 ... 39) -> Ore 1 and 2 can't be used because it's already in this lookup chain

In the end it means to calculate the total raw items using the recipe chain you've setup it needs to do O(N!) lookups where your N is 39. 39! is: 20'397'882'081'197'443'358'640'281'739'902'897'356'800'000'000. Either that or it's O(N^N) which is even worse. I always have trouble conceptualizing big-O time in code.

So about some time after the heat-death of the universe it will finish calculating and show the results.
If you want to get ahold of me I'm almost always on Discord.
Rseding91
Factorio Staff
Factorio Staff
Posts: 14280
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [0.16.51] Crash when hovering mouse above a recipe

Post by Rseding91 »

You can work around the issue by marking your recipes as: don't use this when calculating total raw by setting "allow_decomposition = false" on your recipes.
If you want to get ahold of me I'm almost always on Discord.
pieppiep
Fast Inserter
Fast Inserter
Posts: 170
Joined: Mon Mar 14, 2016 8:52 am
Contact:

Re: [0.16.51] Crash when hovering mouse above a recipe

Post by pieppiep »

So if I understand it correctly the game tries all the 39 recipies in all possible orders, that's O(N!)
That's good to know, because that means I need a factor of 39^39/39! = 5.5*10^15 less cpu cores compared to O(N^N) :D

Thanks for the tip to use allow_decomposition = false
For now I've just changed it to 2*38 recipes. A recipe for each ore type to stone and a recipe for each ore type from stone.

As a software developer myself I'm thinking about how this could be fixed.
The only thing I can come up with is somehow setting a timeout on calculating the raw ingredients.
This can be done by a timeout like x seconds or a timeout by following at most x recipies.
Rseding91
Factorio Staff
Factorio Staff
Posts: 14280
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [0.16.51] Crash when hovering mouse above a recipe

Post by Rseding91 »

pieppiep wrote: Wed Jan 30, 2019 11:03 am As a software developer myself I'm thinking about how this could be fixed.
The only thing I can come up with is somehow setting a timeout on calculating the raw ingredients.
This can be done by a timeout like x seconds or a timeout by following at most x recipies.
That was the only idea I thought of as well.
If you want to get ahold of me I'm almost always on Discord.
Post Reply

Return to “Resolved Problems and Bugs”