From f28d798073e571cb3114208cfa81653b9b502f6c Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Wed, 3 Jun 2015 20:20:37 -0400 Subject: Fix demo desyncs caused by P_RunThinkers() change. 1bcff874c52a changed the behavior of P_RunThinkers() to avoid dereferencing thinker pointers after they had been freed, but the modified version of the function was not logically equivalent to Vanilla version, because the 'next' pointer can be changed by the thinker function if one is invoked. This fixes a desync in tnt-speed-movie-0443131.lmp. Thanks to Zvonimir Bužanić for the bug report and Fabian Greffrath for reporting. Fixes #547. --- src/hexen/p_tick.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/hexen') diff --git a/src/hexen/p_tick.c b/src/hexen/p_tick.c index c58d6e82..3d3dd389 100644 --- a/src/hexen/p_tick.c +++ b/src/hexen/p_tick.c @@ -91,17 +91,18 @@ static void RunThinkers(void) currentthinker = thinkercap.next; while (currentthinker != &thinkercap) { - nextthinker = currentthinker->next; - if (currentthinker->function == (think_t) - 1) { // Time to remove it + nextthinker = currentthinker->next; currentthinker->next->prev = currentthinker->prev; currentthinker->prev->next = currentthinker->next; Z_Free(currentthinker); } - else if (currentthinker->function) + else { - currentthinker->function(currentthinker); + if (currentthinker->function) + currentthinker->function(currentthinker); + nextthinker = currentthinker->next; } currentthinker = nextthinker; -- cgit v1.2.3