Skip to content

Commit 57ffce1

Browse files
authored
Merge pull request #1619 from CitiesSkylinesMods/bugfix/1612-infinite-loop-traversing-node-segments
Infinite loop while traversing segments of node
2 parents c7609e8 + a794094 commit 57ffce1

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

TLM/TLM/Util/Iterators/GetNodeSegmentIdsEnumerator.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public struct GetNodeSegmentIdsEnumerator : IEnumerator<ushort> {
1717

1818
private bool firstRun;
1919
private ushort currentSegmentId;
20+
private int watchdog;
2021

2122
public GetNodeSegmentIdsEnumerator(ushort nodeId, ushort initialSegmentId, ClockDirection clockDirection, NetSegment[] segmentBuffer) {
2223
this.nodeId = nodeId;
@@ -26,6 +27,7 @@ public GetNodeSegmentIdsEnumerator(ushort nodeId, ushort initialSegmentId, Clock
2627

2728
this.firstRun = true;
2829
this.currentSegmentId = default;
30+
this.watchdog = 0;
2931
}
3032

3133
public ushort Current => currentSegmentId;
@@ -38,6 +40,7 @@ public bool MoveNext() {
3840
} else if (firstRun && initialSegment != 0) {
3941
currentSegmentId = initialSegment;
4042
firstRun = false;
43+
watchdog++;
4144
return true;
4245
}
4346

@@ -49,7 +52,7 @@ public bool MoveNext() {
4952
throw new Exception($"Unknown ClockDirection '{nameof(clockDirection)}'");
5053
}
5154

52-
if (currentSegmentId == 0 || currentSegmentId == initialSegment) {
55+
if (currentSegmentId == 0 || currentSegmentId == initialSegment || ++watchdog == Constants.MAX_SEGMENTS_OF_NODE) {
5356
return false;
5457
}
5558

0 commit comments

Comments
 (0)