Train Depot


Automatically clones trains at new advanced train stations called train depots. The train to clone is set by a circuit network signal sent to the station. It can clone schedule and filter settings as well as the carriages. Also adds a combinator that sends a signal counting the number of trains scheduled for a station it is placed next to. Check the mod portal for details on signals and usage.

Content
5 years ago
0.16
5
Trains

b Train Depot crash when placing a Cavern Access Shaft from Surfaces Remake

5 years ago

i had installed the two mods Train Depot and Surfaces Remake (and lots! of others), researched some techs, but used/placed no items from either one, and also had no problems. but starting tests how to use these mods, i just crafted a Cavern Access Shaft (from the other mod) and tried to place it. As a result that item appeared in the world and i immediately got the following crash of this mod:

Error while running event
TrainDepot::on_built_entity (ID 6)
TrainDepot/control.lua:23:attempt to concatenate field 'unit_number' (a nil value)

5 years ago

Thanks for the report! I haven't tried interoperability with other mods yet, so this will give me an opportunity to see what i need to do there.

5 years ago

too bad (or maybe you'll even enjoy this additional opportunity to have some more data on such a crash? :-) here is exactly the same error as above, but as part of a longer crash notice. btw: the other mod didn't give me any crash until now.

Notice
Error while running event
CopyAndPasteModules::on_entity_settings_pasted (ID 31)
Error while running event
TrainDepot::on_built_entity (ID 6)
TrainDepot/control.lua:23:attempt to concatenate field 'unit_number' (a nil value)
stack traceback:
CopyAndPasteModules/control.lua:11:in function 'raise_event'
CopyAndPasteModules/control.lua:671:in function <CopyAndPasteModules/control.lua:215>

5 years ago

https://github.com/taerin-markman/TrainDepot/issues/25

Surfaces_remake breaks a lot of assumptions I've been making, so time to do some cleanup!

5 years ago
(updated 5 years ago)

https://github.com/taerin-markman/TrainDepot/issues/25
Surfaces_remake breaks a lot of assumptions I've been making, so time to do some cleanup!

the first time that i got this crash, it was while placing an item from surfaces remake
the second time, the crash had the longer "notice" including CopyAndPasteModules

when i just got that second crash again while trying to copy the settings of a beacon, i got exactly that second longer notice again. since you mentioned surfaces remake breaking lots of your assumptions, i tried removing surfaces remake and tried again, but even without surfaces remake i got exactly the same error that i listed in the second crash report.

Surfaces remake breaking assumptions might be a reason to check and improve your mod, but unless there were some remains in the save file even after removing surfaces remake, i would assume that this exact crash is not related to surfaces remake but only to CopyAndPasteModules. maybe it breaks the same or other assumptions too :-) :-(

btw: to be able to continue this map, i temporarily removed your mod. i also did the same copy&paste again and this time i got no crash. this seems to confirm that surfaces remake is not the (only) cause of the problem.

ps: best wishes for a continueing recovery !

5 years ago

I’m glad you brought that up. I completely spaced on the presence of CopyAndPasteModules in the trace until you pointed it out and that could explain some of the weirdness. Another mod I’ll have to check out.

5 years ago
(updated 5 years ago)

I'm no modder (only read a few posts) and no LUA programmer (but know some languages), and thus tried havinbg a look myself ... here is the result after a quick google search for "factorio built_entity" :

https://lua-api.factorio.com/latest/events.html shows
on_built_entity - Called when player builds something.
Contains
created_entity :: LuaEntity
player_index :: uint
stack :: LuaItemStack

on_robot_built_entity - Called when a construction robot builds an entity.
Contains
robot :: LuaEntity: The robot that did the building.
created_entity :: LuaEntity: The entity built.
stack :: LuaItemStack: The item used to do the building.

and following the link for created_entity to https://lua-api.factorio.com/0.16.0/LuaEntity.html, i see

unit_number :: uint [R] The unit number or nil if the entity doesn't have one.

in line 21-23, you do an unconditional print :
21: script.on_event({defines.events.on_built_entity, defines.events.on_robot_built_entity}, function(event)
22: local entity = event.created_entity
23: util.print(entity.name .. " placed, unit number: " .. entity.unit_number)

btw: all other print (eg lines 29 & 34) are commented out, but not line 23.
this looks pretty much like a debug command that you forgot ...

you don't check whether the ceated_entity exists or is nil, and most of all you don't check if it has a valid unit_number that is not nil. and if the unit_number is nil, we hit the crash

i have read quite often that a lot can be nil or not exist at all or be not valid, and thus a few extra checks can avoid crashes, while unnecessary checks at most cost minimal additional time to execute.
many mods call on_..._built_entity to allow other mods to do additional handling, eg after modifying something by script, after placing blueprints, etc. and when the properties of entities are copied (including modules, etc), this is probably also the case ...

ps: not directly related to this exact problem, but still an interesting read, related to modifying entities and to having no valid entities on these events: https://forums.factorio.com/viewtopic.php?t=32039

5 years ago

I appreciate the help, Anson_AKB, but I can assure you that both the cause and the fix are no mystery to me.

What is a mystery to me is why an entity would not have a unit_number, which is supposed to be a unique value to identify every entity in game, or so I thought. What I meant in my earlier post is that I just need to load the CopyAndPasteModules mod to find out why it is creating such a thing so I know that I have the complete solution. I actually already have made a fix for the specific issue in your crash report yesterday without even having to know that it was caused by the presence of the CopyAndPasteModules mod (if you're interested, you can check it out here: https://github.com/taerin-markman/TrainDepot/pull/29/commits/3e8b5faf71700583af0bb53425da68b4a69e5d30 ). But, as I said, I want to make sure there aren't other issues before releasing an update.

I have a handle on the issue and just need time to look into these mods to understand what they're doing. Stay tuned.

5 years ago

Try 0.1.3 and let me know how it goes.

5 years ago

thanks for a new version with a possible bugfix, and even for 0.17.
but i finished my last map and now will do the intro missions and a vanilla map first, before all of my important mods are updated.

New response