Science pack dependencies

by Nidan

If a technology doesn't depend (either directly or indirectly) on the science packs it needs, these missing dependecies are added.

Utilities
a month ago
0.15 - 2.0
1.22K

b [Fixed] Attempting to access a nil value

2 years ago
(updated 2 years ago)

Hey!

I really love this mod and this greatly tidies up the research tree with many mods.
Sadly, in some configurations, object in collect_difficulties is nil. I haven't found the code on GitHub or GitLab, then I would have made a pull request/merge request, so I post the fix here:

in collect_difficulties (make_dependencies.lua:216) I added a check, if object is nil:

local function collect_difficulties(difficulties, object, keys)
    if not object then
        return {}
    end

As this is checked on the function entry, I removed the first recursive check, if object[diff] is nil.

Would be amazing if you could do a hotfix :)

Thanks!


The complete function now looks like this:

local function collect_difficulties(difficulties, object, keys)
    if not object then
        return {}
    end

    if difficulties then
        -- we're in data stage and need to handle difficulties
        -- try all difficulties, see if we find our expected keys
        local defined_difficulties = {}
        for diff, _ in pairs(difficulties) do
            local ret = collect_difficulties(nil, object[diff], keys)
            if ret ~= nil then
                table.insert(defined_difficulties, ret[1])
            end
        end
        if #defined_difficulties > 0 then
            return defined_difficulties
        end
    end
    -- no need to handle dificulties, or difficulties weren't defined
    for _, k in pairs(keys) do
        if object[k] ~= nil then
            return {object[k]}
        end
    end
    return {}
end
2 years ago

Thanks for the fix, will take a look at it once I have a bit of free time; probably during the weekend.
Do you have a set of mods that triggers this error?

2 years ago
(updated 2 years ago)

probably during the weekend

Amazing, thanks!


Do you have a set of mods that triggers this error?

The combination of Space Exploration + Kastorio2 + Tin (by Brevven) triggers the error (I disabled all other mods, the stack trace starts at makedependencies (line 581) -> technology_dfs (line 424) -> technology_prerequisites (line 347).

I'm not really experienced in Factorio modding but I guess it's possible to track down the exact research/recipe, which is triggering the error, however, I think the code above is more robust.

2 years ago

I could reproduce the crash. bztin's data-final-fixes adds a technology with a prerequisite that's only added when space-exploration-postprocess' data-final-fixes runs. science-pack-dependencies runs between them and thus sees a reference to a nonexistent technology.
I'll fix this with an order-only dependency on space-exploration-postprocess. In the general case, crashing when seeing references to nonexistent things might actually be what I want so I get notified of ordering issues. Let's see if I can make the crash produce a suitable error message…

2 years ago

Great, thank you!

The fix totally makes sense to me :)

New response