Skip to content

Commit

Permalink
Fix an issue caused unbounded growth of an internal event list
Browse files Browse the repository at this point in the history
  • Loading branch information
dymanoid committed May 31, 2019
1 parent 89710d0 commit 0dd52fe
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/RealTime/Events/RealTimeEventManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public ICityEvent GetCityEvent(ushort buildingId)
/// </summary>
public void ProcessEvents()
{
if (RemoveCanceledEvents())
if (RemoveOldAndCanceledEvents())
{
OnEventsChanged();
}
Expand Down Expand Up @@ -469,17 +469,23 @@ private bool SynchronizeWithVanillaEvent(ushort eventId)
return true;
}

private bool RemoveCanceledEvents()
private bool RemoveOldAndCanceledEvents()
{
bool eventsChanged = false;
for (int i = finishedEvents.Count - 1; i >= 0; --i)
{
if (MustCancelEvent(finishedEvents[i]))
var finishedEvent = finishedEvents[i];
var isOldEvent = finishedEvent.EndTime.Day != timeInfo.Now.Day;
if (isOldEvent || MustCancelEvent(finishedEvent))
{
finishedEvents.RemoveAt(i);
if (!isOldEvent)
{
eventsChanged = true;
}
}
}

bool eventsChanged = false;
for (int i = activeEvents.Count - 1; i >= 0; --i)
{
if (MustCancelEvent(activeEvents[i]))
Expand Down

0 comments on commit 0dd52fe

Please sign in to comment.