Skip to content

Commit 44fa8ad

Browse files
committed
Prevent key not found exception
1 parent d93e863 commit 44fa8ad

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Source/RunActivity/Viewer3D/RollingStock/MSTSLocomotiveViewer.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,16 @@ public override void InitializeUserInputCommands()
196196
() => new TCSButtonCommand(Viewer.Log, false, 0),
197197
() => {
198198
new TCSButtonCommand(Viewer.Log, true, 0);
199-
new TCSSwitchCommand(Viewer.Log, !Locomotive.TrainControlSystem.TCSCommandSwitchOn[0], 0);
199+
Locomotive.TrainControlSystem.TCSCommandSwitchOn.TryGetValue(0, out bool wasPressed);
200+
new TCSSwitchCommand(Viewer.Log, !wasPressed, 0);
200201
}
201202
});
202203
UserInputCommands.Add(UserCommand.ControlTCSGeneric2, new Action[] {
203204
() => new TCSButtonCommand(Viewer.Log, false, 1),
204205
() => {
205206
new TCSButtonCommand(Viewer.Log, true, 1);
206-
new TCSSwitchCommand(Viewer.Log, !Locomotive.TrainControlSystem.TCSCommandSwitchOn[1], 1);
207+
Locomotive.TrainControlSystem.TCSCommandSwitchOn.TryGetValue(1, out bool wasPressed);
208+
new TCSSwitchCommand(Viewer.Log, !wasPressed, 1);
207209
}
208210
});
209211

0 commit comments

Comments
 (0)