components/prboom/p_tick.c
//
// P_RunThinkers
//
// killough 4/25/98:
//
// Fix deallocator to stop using "next" pointer after node has been freed
// (a Doom bug).
//
// Process each thinker. For thinkers which are marked deleted, we must
// load the "next" pointer prior to freeing the node. In Doom, the "next"
// pointer was loaded AFTER the thinker was freed, which could have caused
// crashes.
//
// But if we are not deleting the thinker, we should reload the "next"
// pointer after calling the function, in case additional thinkers are
// added at the end of the list.
//
// killough 11/98:
//
// Rewritten to delete nodes implicitly, by making currentthinker
// external and using P_RemoveThinkerDelayed() implicitly.
//


Fix deallocator to stop using "next" pointer after node has been freed
(a Doom bug).

Process each thinker. For thinkers which are marked deleted, we must
load the "next" pointer prior to freeing the node. In Doom, the "next"
pointer was loaded AFTER the thinker was freed, which could have caused
crashes.

But if we are not deleting the thinker, we should reload the "next"
pointer after calling the function, in case additional thinkers are
added at the end of the list.



Rewritten to delete nodes implicitly, by making currentthinker
external and using P_RemoveThinkerDelayed() implicitly.
Fix deallocator to stop using " next " pointer after node has been freed ( a Doom bug ) . Process each thinker . For thinkers which are marked deleted we must load the " next " pointer prior to freeing the node . In Doom the " next " pointer was loaded AFTER the thinker was freed which could have caused crashes . But if we are not deleting the thinker we should reload the " next " pointer after calling the function in case additional thinkers are added at the end of the list . Rewritten to delete nodes implicitly by making currentthinker external and using P_RemoveThinkerDelayed () implicitly .
static void P_RunThinkers (void)
{
  for (currentthinker = thinkercap.next;
       currentthinker != &thinkercap;
       currentthinker = currentthinker->next)
  {
    if (newthinkerpresent)
      R_ActivateThinkerInterpolations(currentthinker);
    if (currentthinker->function)
      currentthinker->function(currentthinker);
  }
  newthinkerpresent = false;
}
static void P_RunThinkers ( void ) { for ( currentthinker = thinkercap . next ; currentthinker != & thinkercap ; currentthinker = currentthinker -> next ) { if ( newthinkerpresent ) R_ActivateThinkerInterpolations ( currentthinker ) ; if ( currentthinker -> function ) currentthinker -> function ( currentthinker ) ; } newthinkerpresent = false ; }
P_RunThinkers
killough 4/25/98:
P_RunThinkers killough 4 / 25 / 98 :