@@ -131,22 +131,42 @@ public CurrentRoute(BaseRenderer renderer)
131
131
/// <summary>Updates all sections within the route</summary>
132
132
public void UpdateAllSections ( )
133
133
{
134
- UpdateSection ( Sections . LastOrDefault ( ) ) ;
134
+ /*
135
+ * When there are an insane amount of sections, updating via a reference chain
136
+ * may trigger a StackOverflowException
137
+ *
138
+ * Instead, pull out the reference to the next section in an out variable
139
+ * and use a while loop
140
+ * https://github.com/leezer3/OpenBVE/issues/557
141
+ */
142
+ Section nextSectionToUpdate ;
143
+ UpdateSection ( Sections . LastOrDefault ( ) , out nextSectionToUpdate ) ;
144
+ while ( nextSectionToUpdate != null )
145
+ {
146
+ UpdateSection ( nextSectionToUpdate , out nextSectionToUpdate ) ;
147
+ }
135
148
}
136
149
137
150
/// <summary>Updates the specified signal section</summary>
138
151
/// <param name="SectionIndex"></param>
139
152
public void UpdateSection ( int SectionIndex )
140
153
{
141
- UpdateSection ( Sections [ SectionIndex ] ) ;
154
+ Section nextSectionToUpdate ;
155
+ UpdateSection ( Sections [ SectionIndex ] , out nextSectionToUpdate ) ;
156
+ while ( nextSectionToUpdate != null )
157
+ {
158
+ UpdateSection ( nextSectionToUpdate , out nextSectionToUpdate ) ;
159
+ }
142
160
}
143
161
144
162
/// <summary>Updates the specified signal section</summary>
145
163
/// <param name="Section"></param>
146
- public void UpdateSection ( Section Section )
164
+ /// <param name="PreviousSection"></param>
165
+ public void UpdateSection ( Section Section , out Section PreviousSection )
147
166
{
148
167
if ( Section == null )
149
168
{
169
+ PreviousSection = null ;
150
170
return ;
151
171
}
152
172
@@ -355,7 +375,7 @@ public void UpdateSection(Section Section)
355
375
Section . CurrentAspect = newAspect ;
356
376
357
377
// update previous section
358
- UpdateSection ( Section . PreviousSection ) ;
378
+ PreviousSection = Section . PreviousSection ;
359
379
}
360
380
361
381
/// <summary>Updates the currently displayed background</summary>
0 commit comments