Skip to content

Commit eadd082

Browse files
committed
Fix adding events to the standard TrItems array.
This fix collects the events in a list, and at the end resizes the array and adds the events. The existing code already counts the number of events (in cnt). Thus the array could be extended before the second loop over activities, and the events added directly.
1 parent e57a7a1 commit eadd082

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

Source/Contrib/TrackViewer/Drawing/DrawTrackDB.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ public RouteData(string routePath, MessageDelegate messageDelegate)
137137
}
138138

139139
// adding
140-
uint index = 0;
140+
int index = TrackDB.TrItemTable.Length;
141+
List<TrItem> eventItems = new List<TrItem>();
141142
foreach (var file in Directory.GetFiles(directory, "*.act"))
142143
{
143144
try
@@ -157,8 +158,8 @@ public RouteData(string routePath, MessageDelegate messageDelegate)
157158
eventCategoryLocation.Outcomes.DisplayMessage,
158159
eventCategoryLocation.TileX, eventCategoryLocation.TileZ,
159160
eventCategoryLocation.X, 0, eventCategoryLocation.Z,
160-
index);
161-
TrackDB.TrItemTable[index] = eventItem;
161+
(uint)index);
162+
eventItems.Add(eventItem);
162163
index++;
163164
found = true;
164165
}
@@ -171,6 +172,12 @@ public RouteData(string routePath, MessageDelegate messageDelegate)
171172
catch { }
172173
}
173174

175+
// extend the track items array and append the event items
176+
int oldSize = TrackDB.TrItemTable.Length;
177+
Array.Resize<TrItem>(ref TrackDB.TrItemTable, index);
178+
int newSize = TrackDB.TrItemTable.Length;
179+
int eventSize = eventItems.Count;
180+
for (int toIdx = oldSize, fromIdx = 0; toIdx < newSize && fromIdx < eventSize; toIdx++, fromIdx++) { TrackDB.TrItemTable[toIdx] = eventItems[fromIdx]; }
174181
}
175182
}
176183

0 commit comments

Comments
 (0)