Skip to content

Commit

Permalink
Fixed bug where a timer deleting a timer might crash the client
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgammon committed Jun 16, 2010
1 parent dcde8f5 commit 40eed91
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions doc.cpp
Expand Up @@ -4443,7 +4443,9 @@ double t = (tNow.m_dt - ((int) tNow.m_dt) ) * 86400.0;
}
}

// iterate through all timers for this document
CStringList firedTimersList;

// iterate through all timers for this document - first build list of them

for (POSITION pos = TimerMap.GetStartPosition(); pos; )
{
Expand All @@ -4454,17 +4456,34 @@ double t = (tNow.m_dt - ((int) tNow.m_dt) ) * 86400.0;
if (!timer_item->bEnabled) // ignore un-enabled timers
continue;

// no timer activity whilst closed or in the middle of connecting, or if not enabled
// no timer activity whilst closed or in the middle of connecting, or if not enabled

if (!timer_item->bActiveWhenClosed)
if (m_iConnectPhase != eConnectConnectedToMud)
continue;
if (!timer_item->bActiveWhenClosed)
if (m_iConnectPhase != eConnectConnectedToMud)
continue;

// if not ready to fire yet, ignore it
// if not ready to fire yet, ignore it

if (timer_item->tFireTime > tNow)
continue;

firedTimersList.AddTail (strTimerName); // add to list of fired timers

}


// now process list, checking timer still exists in case a script deleted one
// see: http://www.gammon.com.au/forum/?id=10358

for (pos = firedTimersList.GetHeadPosition (); pos; )
{
// get next fired timer from list
strTimerName = m_strMapList.GetNext (pos);

// check still exists, get pointer if so
if (!TimerMap.Lookup (strTimerName, timer_item))
continue;

timer_item->nMatched++; // count timer matches
timer_item->tWhenFired = tNow; // when it fired

Expand Down

0 comments on commit 40eed91

Please sign in to comment.