shithub: choc

Download patch

ref: 8993063b126c65e572944ca487f5b980abfcf60d
parent: 125acd0ef3c0c7a4b9db6d82f302d9d8bbd17d42
author: Fabian Greffrath <fabian@greffrath.com>
date: Mon Oct 26 03:35:06 EDT 2015

Add error message for linedefs referencing non-existent sidedefs

This is a severe mapping error that leads to reading invalid memory
and will thus crash sooner or later. Since this cannot be properly
emulated, do what PrBoom+ does and error out with a message instead
of letting the game crash.

Fixes #624

--- a/src/doom/p_setup.c
+++ b/src/doom/p_setup.c
@@ -198,6 +198,14 @@
 	ldef = &lines[linedef];
 	li->linedef = ldef;
 	side = SHORT(ml->side);
+
+        // e6y: check for wrong indexes
+        if ((unsigned)ldef->sidenum[side] >= (unsigned)numsides)
+        {
+            I_Error("P_LoadSegs: linedef %d for seg %d references a non-existent sidedef %d",
+                    linedef, i, (unsigned)ldef->sidenum[side]);
+        }
+
 	li->sidedef = &sides[ldef->sidenum[side]];
 	li->frontsector = sides[ldef->sidenum[side]].sector;