Open adlerd opened 1 year ago
Suggested patch, not tested:
--- cybersyn/scripts/gui.lua
+++ cybersyn/scripts/gui.lua
@@ -91,8 +91,8 @@
set_comb_operation(comb, MODE_DEPOT)
--prevent the use of the each signal with depots
local network = element.parent.parent.bottom.network--[[@as LuaGuiElement]]
local signal = network.elem_value--[[@as SignalID]]
- if signal.name == NETWORK_EACH then
+ if signal and (signal.name == NETWORK_EACH) then
network.elem_value = nil
set_comb_network_name(comb, nil)
end
Additional bug related to the same code (but probably not fixed with above patch):
Place train stop, combinator. Select "EACH" signal. Select "Depot" mode. Per the above code snippet, signal is cleared. Now open the dropdown again. The dropdown visually opens but then the game immediately crashes to menu with:
Error while running event cybersyn::on_gui_click (ID 1)
__cybersyn__/scripts/gui.lua:95: attempt to index local 'signal' (a nil value)
stack traceback:
__cybersyn__/scripts/gui.lua:95: in function 'handler'
__flib__/gui-lite.lua:169: in function <__flib__/gui-lite.lua:152>
This is perhaps worse because the user never cleared the signal, so maybe is less culpable in causing the crash ;)
Verified this fix works. I'll create a PR with the patch unless you want to @adlerd?
Error message:
Repro steps: Place a train stop and a cybersyn combinator facing it. Open the GUI; it will be in station mode by default. Right-click the signal selection ("virtual-A" by default) to clear it. Then use the drop-down to switch the combinator to depot mode. The game will immediately crash to main menu with the above message.
NB. The reason this can come up is it's nice to clear out the signal for non-station combinators, so that there's not a spurious "A" on the combinator graphics in alt-mode (maybe plus the relevant game setting to make combinators show signals in alt-mode?).