Page 1 of 1

[0.16.16] Game freezes on very simple mod script

Posted: Thu Jan 11, 2018 9:47 pm
by Reika
The scripting code in question is very simple and innocuous, but even if it has an error - somehow - there is at least a sandboxing failure because the game is not supposed to completely lock up like that.

The code in question is this:

Code: Select all

local function onEntityAdded(entity)
	if string.find(entity.name, "depot-placer", 1, true) then
		local depot = global.depot
		local type = string.match(entity.name, "%d+")
		local render = entity.surface.create_entity({name = "depot-render-type-" .. type, position = entity.position, force = entity.force})
		local storage = entity.surface.create_entity({name = "depot-type-" .. type, position = entity.position, force = entity.force})
		local entry = {main = storage, placer = entity, render = render, type = type}
		table.insert(depot.entries, entry)
	end
end
The actual line triggering the freeze is that last one, the table.insert. Removing it fixes the issue. I cannot imagine what I might be doing wrong; I have done this sort of thing 40 times and all it is doing is adding an entry to the global data table.

I checked the obvious solution of a runaway loop; that is not in fact occurring (the function is only ever called once).

As for the freeze, memory usage is not continuously climbing, so it is not a runaway allocation. But one CPU core does get maxed out. The only way to recover is to use Task Manager to kill the process.

The log contains nothing of value, with the last line being related to the world loading, and nothing being printed after that.


This code is for the idea described here.

Re: [0.16.16] Game freezes on very simple mod script

Posted: Thu Jan 11, 2018 10:15 pm
by Rseding91
Can you upload a mod and steps that shows the issue?

Re: [0.16.16] Game freezes on very simple mod script

Posted: Thu Jan 11, 2018 10:37 pm
by Reika
Rseding91 wrote:Can you upload a mod and steps that shows the issue?
The mod in question is attached. Simply spawn a "depot-type-1" using game.player.insert and place it.

Re: [0.16.16] Game freezes on very simple mod script

Posted: Thu Jan 11, 2018 10:52 pm
by Rseding91
Thanks for the mod. I've fixed the crash for the next version of 0.16.

You've set weight, friction_force, and braking_force to 0 on a cargo wagon entity which isn't valid as those values are used in division resulting in division by zero.

In the next version of 0.16 it will check that they're > 0 and error on startup if they aren't.

Re: [0.16.16] Game freezes on very simple mod script

Posted: Thu Jan 11, 2018 11:18 pm
by Reika
Rseding91 wrote:Thanks for the mod. I've fixed the crash for the next version of 0.16.

You've set weight, friction_force, and braking_force to 0 on a cargo wagon entity which isn't valid as those values are used in division resulting in division by zero.

In the next version of 0.16 it will check that they're > 0 and error on startup if they aren't.
Fair enough - why did that make the table.insert throw the error, and not the creation of the entity?

Re: [0.16.16] Game freezes on very simple mod script

Posted: Fri Jan 12, 2018 1:36 am
by Rseding91
Reika wrote:
Rseding91 wrote:Thanks for the mod. I've fixed the crash for the next version of 0.16.

You've set weight, friction_force, and braking_force to 0 on a cargo wagon entity which isn't valid as those values are used in division resulting in division by zero.

In the next version of 0.16 it will check that they're > 0 and error on startup if they aren't.
Fair enough - why did that make the table.insert throw the error, and not the creation of the entity?
Division by zero is undefined behavior in C++ so where it breaks and what happens when it happens is also undefined.

When I tested it on my computer it didn't error in that line of code but somewhere else and only sometimes. I'm not sure why it errors on that line for you.