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

This subforum contains all the issues which we already resolved.
Post Reply
User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

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

Post 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.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!

keyboardhack
Filter Inserter
Filter Inserter
Posts: 478
Joined: Sat Aug 23, 2014 11:43 pm
Contact:

Re: [0.12.19] crash with too many invalid prototypes

Post 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},
Waste of bytes : P

User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: [0.12.19] crash with too many invalid prototypes

Post by prg »

Well, thanks, but check the original post I linked.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!

Oxyd
Former Staff
Former Staff
Posts: 1428
Joined: Thu May 07, 2015 8:42 am
Contact:

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

Post 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.

Post Reply

Return to “Resolved Problems and Bugs”