foxygit / doom Log in
commit 1112fd9573f8d45e167e1ba7cbe35a0f18aa5910
Author:     James Haley <haleyjd@hotmail.com>
AuthorDate: Fri Aug 26 21:09:51 2016 -0500
Commit:     James Haley <haleyjd@hotmail.com>
CommitDate: Fri Aug 26 21:09:51 2016 -0500

    Overflow safety for solidsegs; hopefully interim.
---
 src/doom/r_bsp.c    | 14 ++++++++++++--
 src/heretic/r_bsp.c | 13 ++++++++++++-
 src/hexen/r_bsp.c   | 13 ++++++++++++-
 src/strife/r_bsp.c  | 14 ++++++++++++--
 4 files changed, 48 insertions(+), 6 deletions(-)

diff --git a/src/doom/r_bsp.c b/src/doom/r_bsp.c
index 9a788122..755d2eef 100644
--- a/src/doom/r_bsp.c
+++ b/src/doom/r_bsp.c
@@ -77,8 +77,14 @@ typedef	struct

 } cliprange_t;

-
-#define MAXSEGS		32
+// We must expand MAXSEGS to the theoretical limit of the number of solidsegs
+// that can be generated in a scene by the DOOM engine. This was determined by
+// Lee Killough during BOOM development to be a function of the screensize.
+// The simplest thing we can do, other than fix this bug, is to let the game
+// render overage and then bomb out by detecting the overflow after the
+// fact. -haleyjd
+//#define MAXSEGS 32
+#define MAXSEGS (SCREENWIDTH / 2 + 1)

 // newend is one past the last valid seg
 cliprange_t*	newend;
@@ -532,6 +538,10 @@ void R_Subsector (int num)
 	R_AddLine (line);
 	line++;
     }
+
+    // check for solidsegs overflow - extremely unsatisfactory!
+    if(newend > &solidsegs[32])
+        I_Error("R_Subsector: solidsegs overflow (vanilla may crash here)\n");
 }


diff --git a/src/heretic/r_bsp.c b/src/heretic/r_bsp.c
index d2e404ba..53333aac 100644
--- a/src/heretic/r_bsp.c
+++ b/src/heretic/r_bsp.c
@@ -58,7 +58,14 @@ typedef struct
     int first, last;
 } cliprange_t;

-#define	MAXSEGS	32
+// We must expand MAXSEGS to the theoretical limit of the number of solidsegs
+// that can be generated in a scene by the DOOM engine. This was determined by
+// Lee Killough during BOOM development to be a function of the screensize.
+// The simplest thing we can do, other than fix this bug, is to let the game
+// render overage and then bomb out by detecting the overflow after the
+// fact. -haleyjd
+//#define MAXSEGS 32
+#define MAXSEGS (SCREENWIDTH / 2 + 1)

 cliprange_t solidsegs[MAXSEGS], *newend;        // newend is one past the last valid seg

@@ -437,6 +444,10 @@ void R_Subsector(int num)
         R_AddLine(line);
         line++;
     }
+
+    // check for solidsegs overflow - extremely unsatisfactory!
+    if(newend > &solidsegs[32])
+        I_Error("R_Subsector: solidsegs overflow (vanilla may crash here)\n");
 }


diff --git a/src/hexen/r_bsp.c b/src/hexen/r_bsp.c
index ece47a92..cae9cbfd 100644
--- a/src/hexen/r_bsp.c
+++ b/src/hexen/r_bsp.c
@@ -59,7 +59,14 @@ typedef struct
     int first, last;
 } cliprange_t;

-#define MAXSEGS 32
+// We must expand MAXSEGS to the theoretical limit of the number of solidsegs
+// that can be generated in a scene by the DOOM engine. This was determined by
+// Lee Killough during BOOM development to be a function of the screensize.
+// The simplest thing we can do, other than fix this bug, is to let the game
+// render overage and then bomb out by detecting the overflow after the
+// fact. -haleyjd
+//#define MAXSEGS 32
+#define MAXSEGS (SCREENWIDTH / 2 + 1)

 cliprange_t solidsegs[MAXSEGS], *newend;        // newend is one past the last valid seg

@@ -458,6 +465,10 @@ void R_Subsector(int num)
         R_AddLine(line);
         line++;
     }
+
+    // check for solidsegs overflow - extremely unsatisfactory!
+    if(newend > &solidsegs[32])
+        I_Error("R_Subsector: solidsegs overflow (vanilla may crash here)\n");
 }


diff --git a/src/strife/r_bsp.c b/src/strife/r_bsp.c
index d335d0bb..64b9d5df 100644
--- a/src/strife/r_bsp.c
+++ b/src/strife/r_bsp.c
@@ -77,8 +77,14 @@ typedef	struct

 } cliprange_t;

-
-#define MAXSEGS		32
+// We must expand MAXSEGS to the theoretical limit of the number of solidsegs
+// that can be generated in a scene by the DOOM engine. This was determined by
+// Lee Killough during BOOM development to be a function of the screensize.
+// The simplest thing we can do, other than fix this bug, is to let the game
+// render overage and then bomb out by detecting the overflow after the
+// fact. -haleyjd
+//#define MAXSEGS		32
+#define MAXSEGS (SCREENWIDTH / 2 + 1)

 // newend is one past the last valid seg
 cliprange_t*	newend;
@@ -532,6 +538,10 @@ void R_Subsector (int num)
 	R_AddLine (line);
 	line++;
     }
+
+    // check for solidsegs overflow - extremely unsatisfactory!
+    if(newend > &solidsegs[32])
+        I_Error("R_Subsector: solidsegs overflow (vanilla may crash here)\n");
 }