Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when Resource is not set and Circuits are used #36

EugeneKay opened this issue Sep 9, 2019 · 2 comments


Copy link

commented Sep 9, 2019

I have encountered a crash repeatably while designing a train station using this mod. The crash occurs in or near the same tick as the train stop being "Enabled" via circuit condition. I have not been able to reproduce this in a minimal save file (using less mods). The crash can be reproduced by placing an additional 100 "Speed Module 8" (available in the character's inventory) into either of the two chests to the East of the character (attached to the stop known as Extra[item=]. Save File:

The exact error message produced is:

Error while running event SamTrain::on_nth_tick(120)
__SamTrain__/scripts/conductor.lua:35: bad argument #1 of 2 to 'pairs' (table expected, got nil)
stack traceback:
	[C]: in function 'pairs'
	__SamTrain__/scripts/conductor.lua:35: in function 'get_resource_for_train_stop'
	__SamTrain__/scripts/conductor.lua:218: in function 'build_suppliers'
	__SamTrain__/scripts/conductor.lua:252: in function 'tick'
	__SamTrain__/scripts/conductor.lua:636: in function <__SamTrain__/scripts/conductor.lua:635>

The crash does not occur if there is a "Resource" set in the attached Train Stop Supplier. It also does not occur if all of the circuits are disconnected from the Train Stop. Notably, this is happening with the stop in the not-Enabled state.

Looking at the code in question (, it looks like the for loop is not able to handle signal becoming empty (the red-wire goes 'dark'). This probably also happens with the Green circuit network, but I did not test.

Thanks for looking! I am really enjoying this mod. It is proving much simpler to implement round-robin train logic than trying to do it with Circuit conditions alone. ;-)


This comment has been minimized.

Copy link

commented Sep 9, 2019

Thanks for such a comprehensive bug report. I'm at work so can't test, but have guarded against circuit_network.signals being nil

Heres a build for you to test if you like, otherwise I will be checking tonight :)

@kiasyn kiasyn self-assigned this Sep 9, 2019


This comment has been minimized.

Copy link

commented Sep 9, 2019

Glad to help! The test build did not crash under the same conditions, so the fix works. I will probably find more small problems through the course of this week. I am relatively new to Lua API modding or I would have submitted a Pull Request myself. I'll see what else happens over the course of this week as I work on this new map (still Sunday night for me! Few more hours of freedom!). Thanks again, I am amazed at the quick response!

@kiasyn kiasyn closed this in d440e34 Sep 9, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.