Game closes when loading mod, log contains no useful info

Place to get help with not working mods / modding interface.
User avatar
Reika
Filter Inserter
Filter Inserter
Posts: 587
Joined: Tue May 19, 2015 1:56 am
Contact:

Game closes when loading mod, log contains no useful info

Post by Reika »

I am working on making an infinite-research mod (automatically adding levels of various researches) but when loading it the game closes as soon as the mod starts loading (without an error dialog), and the log simply terminates after "loading mod InfiTech".

Here is my relevant code:

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.name},
    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

Code: Select all

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
As you can see from the debug code for "max", no matter what the max research level I add is, the game crashes, so it is not simply choking on adding thousands of researches, or on costs that reach millions.
Last edited by Reika on Sat Nov 28, 2015 1:38 am, edited 1 time in total.
Image
User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: Game closes when loading mod, log contains no useful info

Post by prg »

For me this results in *** Error in `./factorio': realloc(): invalid next size: 0x000000000322be60 ***. No matter what you're doing wrong, this shouldn't happen. You might want to go for a bug report.

Things start working if you assign base_tech.name to prerequisites instead of just base_tech.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!
User avatar
Reika
Filter Inserter
Filter Inserter
Posts: 587
Joined: Tue May 19, 2015 1:56 am
Contact:

Re: Game closes when loading mod, log contains no useful info

Post by Reika »

prg wrote:For me this results in *** Error in `./factorio': realloc(): invalid next size: 0x000000000322be60 ***. No matter what you're doing wrong, this shouldn't happen. You might want to go for a bug report.

Things start working if you assign base_tech.name to prerequisites instead of just base_tech.
Still not for me, though I fixed the original post to reflect the correction.

That said, with some playing around, I was able to get this:
Error Util.cpp:49: Error while loading technology prototype "character-logistic-slots-774" (technology): conversion of data to type "double" failed
Modifications: InfiTech
Thinking that this might be numerical overflow, I checked the cost of that research, which comes out to approximately 10^308. Yes, absolutely massive, but why that of all numbers? Surely that is well after any kind of overflow would have occurred (i.e. any overflow would have already happened on a number many orders of magnitude smaller)?

That said, cutting "max" to 250 does fix the issue...

EDIT: Loading it ingame (some more tweaks got it working) does confirm the functional limit at standard Int.MAX (2^31-1 = 2.147B) values. I have some fixing to do.Image

Image
Image
daniel34
Global Moderator
Global Moderator
Posts: 2761
Joined: Thu Dec 25, 2014 7:30 am
Contact:

Re: Game closes when loading mod, log contains no useful info

Post by daniel34 »

Reika wrote:
Error Util.cpp:49: Error while loading technology prototype "character-logistic-slots-774" (technology): conversion of data to type "double" failed
Modifications: InfiTech
Thinking that this might be numerical overflow, I checked the cost of that research, which comes out to approximately 10^308. Yes, absolutely massive, but why that of all numbers? Surely that is well after any kind of overflow would have occurred (i.e. any overflow would have already happened on a number many orders of magnitude smaller)?
The data type double (signed) has a limit of 1.7 x 10^308, so I guess you went a bit too far with your infinite research :)
Although I'm wondering why it is converted to a double before later converting it to int (loss of precision).
quick links: log file | graphical issues | wiki
User avatar
Reika
Filter Inserter
Filter Inserter
Posts: 587
Joined: Tue May 19, 2015 1:56 am
Contact:

Re: Game closes when loading mod, log contains no useful info

Post by Reika »

daniel34 wrote:
Reika wrote:
Error Util.cpp:49: Error while loading technology prototype "character-logistic-slots-774" (technology): conversion of data to type "double" failed
Modifications: InfiTech
Thinking that this might be numerical overflow, I checked the cost of that research, which comes out to approximately 10^308. Yes, absolutely massive, but why that of all numbers? Surely that is well after any kind of overflow would have occurred (i.e. any overflow would have already happened on a number many orders of magnitude smaller)?
The data type double (signed) has a limit of 1.7 x 10^308, so I guess you went a bit too far with your infinite research :)
Although I'm wondering why it is converted to a double before later converting it to int (loss of precision).
That is what tripped me up too. I know lua (annoyingly) does not type its numbers, but I was expecting an automatic parsing into an int (which does eventually happen, but only for ingame purposes, not during loading). Then again, I have no idea how the lua data is meshed into the raw C++ code.

At any rate, I ended up fixing it by making the exponent gradually reduce as the cost goes higher and higher.
Image
Post Reply

Return to “Modding help”