Page 1 of 1

[0.12.19][Oxyd] crash with too many invalid prototypes

Posted: Sun Nov 29, 2015 11:28 pm
by prg
As noticed in https://forums.factorio.com/forum/vie ... 25&t=18080, the game crashes with *** Error in `./factorio': realloc(): invalid next size: 0x000000000322be60 *** when putting this code in data.lua:

Code: Select all

    function create_Tech(level, parent_name, linear, exponent)

      --some name calculation
      local post = "-" .. (level-1)
      local new_post = "-" .. level
      parent_name = parent_name .. post
      local base_tech = data.raw["technology"][parent_name]
      if base_tech == nil then
       error(serpent.block("Could not create level " .. level .. " of tech, parent '" .. parent_name .. "' does not exist.")) --equivalent to 'throw new RuntimeException(sg)', since print, aka System.out.println(sg), does not work
      end
      local idx = base_tech.name:match'^.*()-' --equivalent to 'lastIndexOf('-')'
      local new_name = string.sub(base_tech.name, 1, idx-1) .. new_post --equivalent to 'base_tech.substring(0, idx-1)'
     
      -- if tech exists (eg a mod) do not override it
      if data.raw["technology"][new_name] then
       return nil
      end
     
      --actual tech
      local result =
      {
        type = "technology",
        name = new_name,
        icon = base_tech.icon,
        effects = base_tech.effects,
        prerequisites = base_tech,
        unit =
        {
          ingredients = base_tech.unit.ingredients,
          time = math.floor(base_tech.unit.time*(1+(exponent-1)/4)),
         count = math.floor(base_tech.unit.count*exponent+linear),
        },
        upgrade = true,
        order = "e-p-b-c"
      } 
     
      --debug line
      --error(serpent.block("Created tech level " .. level .. ", name = " .. new_name))
      print("Created tech level " .. level .. ", name = " .. new_name .. ": ") --only prints if run from command line
     
      return result
    end

--     require("functions")

    local max = 25--1000--50

    for i=21,max do
    local tech = create_Tech(i, "follower-robot-count", 200, 1)
       if tech ~= nil then
          data:extend(
          {
            tech
          })
       end
    end

    for i=5,max do
    local tech = create_Tech(i, "research-effectivity", 0, 2)
       if tech ~= nil then
          data:extend(
          {
            tech
          })
       end
    end

    for i=5,max do
    local tech = create_Tech(i, "inserter-stack-size-bonus", 100, 1.1)
       if tech ~= nil then
          data:extend(
          {
            tech
          })
       end
    end

    for i=6,max do
    local tech = create_Tech(i, "logistic-robot-speed", 250, 2)
       if tech ~= nil then
          data:extend(
          {
            tech
          })
       end
    end

    for i=4,max do
    local tech = create_Tech(i, "logistic-robot-storage", 150, 1.25)
       if tech ~= nil then
          data:extend(
          {
            tech
          })
       end
    end

    for i=6,max do
    local tech = create_Tech(i, "character-logistic-slots", 100, 2.5)
       if tech ~= nil then
          data:extend(
          {
            tech
          })
       end
    end
When only defining a few prototypes in this way you get a proper error message, "Error while loading technology prototype "follower-robot-count-21" (technology): Empty id of technology prerequisite." so I guess this is a case of too many errors accumulating or something.

Re: [0.12.19] crash with too many invalid prototypes

Posted: Mon Nov 30, 2015 2:12 am
by keyboardhack
Factorio should certainly not give that first error.
While waiting for the bug to be fixed i think i found what is wrong with the script in case you haven't found it yet.


Line 26 in the code you posted above

Code: Select all

prerequisites = base_tech,
i believe it's supposed to be something like this

Code: Select all

prerequisites = {base_tech.name},

Re: [0.12.19] crash with too many invalid prototypes

Posted: Mon Nov 30, 2015 7:25 am
by prg
Well, thanks, but check the original post I linked.

Re: [0.12.19][Oxyd] crash with too many invalid prototypes

Posted: Mon Nov 30, 2015 3:03 pm
by Oxyd
prg wrote:When only defining a few prototypes in this way you get a proper error message, "Error while loading technology prototype "follower-robot-count-21" (technology): Empty id of technology prerequisite." so I guess this is a case of too many errors accumulating or something.
It's a case of the Lua stack overflowing whilst trying to make a deep copy of the Lua state somewhere in the game.

Fixed in 0.12.20.