[0.16.16] Game freezes on very simple mod script

This subforum contains all the issues which we already resolved.
User avatar
Reika
Filter Inserter
Filter Inserter
Posts: 583
Joined: Tue May 19, 2015 1:56 am
Contact:

[0.16.16] Game freezes on very simple mod script

Post 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.
Image
Rseding91
Factorio Staff
Factorio Staff
Posts: 14405
Joined: Wed Jun 11, 2014 5:23 am
Contact:

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

Post by Rseding91 »

Can you upload a mod and steps that shows the issue?
If you want to get ahold of me I'm almost always on Discord.
User avatar
Reika
Filter Inserter
Filter Inserter
Posts: 583
Joined: Tue May 19, 2015 1:56 am
Contact:

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

Post 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.
Attachments
Depot_0.0.1.rar
(8.56 KiB) Downloaded 123 times
Image
Rseding91
Factorio Staff
Factorio Staff
Posts: 14405
Joined: Wed Jun 11, 2014 5:23 am
Contact:

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

Post 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.
If you want to get ahold of me I'm almost always on Discord.
User avatar
Reika
Filter Inserter
Filter Inserter
Posts: 583
Joined: Tue May 19, 2015 1:56 am
Contact:

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

Post 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?
Image
Rseding91
Factorio Staff
Factorio Staff
Posts: 14405
Joined: Wed Jun 11, 2014 5:23 am
Contact:

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

Post 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.
If you want to get ahold of me I'm almost always on Discord.
Post Reply

Return to “Resolved Problems and Bugs”