Skip to content

Duke3D: Fix crash during demo playback caused by a mistake in 5132b41f

Dino Bollinger requested to merge dibollinger/eduke32:democrash_fix into master

Fixes #78 (closed)

I found the needle in the haystack, the following change in source/duke3d/src/savegame.cpp in commit 5132b41f was at fault:

@@ -924,46 +923,60 @@ static void docmpsd(const void *ptr, void *dump, uint32_t size, uint32_t cnt, ui
 // get the number of elements to be monitored for changes
 static int32_t getnumvar(const dataspec_t *spec)
 {
-    int32_t n=0;
-    for (; spec->flags!=DS_END; spec++)
-        n += (spec->flags&(DS_STRING|DS_CMP|DS_NOCHK|DS_SAVEFN|DS_LOADFN) ? 0 : 1);
+    int n = 0;
+    for (; spec->flags != DS_END; spec++)
+        if (spec->flags & (DS_STRING|DS_CMP|DS_NOCHK|DS_SAVEFN|DS_LOADFN))
+            ++n;
     return n;
 }

Originally n would be incremented whenever the condition was false, but after commit 5132b41f it was incremented if true.

Reverting this solves the crash.

Merge request reports