ref: 22d473c19cddb35c8ba90fbe52beb7dff8377688
parent: c131d939ed389ac381853f904fa8d09ec1100aac
author: Simon Howard <[email protected]>
date: Tue Jun 12 14:49:29 EDT 2007
Emulate overflows in P_FindNextHighestFloor. Thanks to entryway for this fix. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 902
--- a/NEWS
+++ b/NEWS
@@ -132,6 +132,8 @@
means that people with non-US keyboards can decide whether to use
their correct native mapping or behave like Vanilla mapping (which
assumes all keyboards are US).
+ * Emulate overflow bug in P_FindNextHighestFloor. Thanks to
+ entryway for the fix for this.
Bugs fixed:
* Fix crash when starting new levels due to the intermission screen
--- a/src/p_spec.c
+++ b/src/p_spec.c
@@ -328,58 +328,69 @@
// FIND NEXT HIGHEST FLOOR IN SURROUNDING SECTORS
// Note: this should be doable w/o a fixed array.
+// Thanks to entryway for the Vanilla overflow emulation.
+
// 20 adjoining sectors max!
-#define MAX_ADJOINING_SECTORS 20
+#define MAX_ADJOINING_SECTORS 20
fixed_t
P_FindNextHighestFloor
-( sector_t* sec,
- int currentheight )
+( sector_t* sec,
+ int currentheight )
{
- int i;
- int h;
- int min;
- line_t* check;
- sector_t* other;
- fixed_t height = currentheight;
+ int i;
+ int h;
+ int min;
+ line_t* check;
+ sector_t* other;
+ fixed_t height = currentheight;
+ fixed_t heightlist[MAX_ADJOINING_SECTORS + 2];
-
- fixed_t heightlist[MAX_ADJOINING_SECTORS];
-
- for (i=0, h=0 ;i < sec->linecount ; i++)
+ for (i=0, h=0; i < sec->linecount; i++)
{
- check = sec->lines[i];
- other = getNextSector(check,sec);
+ check = sec->lines[i];
+ other = getNextSector(check,sec);
- if (!other)
- continue;
-
- if (other->floorheight > height)
- heightlist[h++] = other->floorheight;
+ if (!other)
+ continue;
+
+ if (other->floorheight > height)
+ {
+ // Emulation of memory (stack) overflow
+ if (h == MAX_ADJOINING_SECTORS + 1)
+ {
+ height = other->floorheight;
+ }
+ else if (h == MAX_ADJOINING_SECTORS + 2)
+ {
+ // Fatal overflow: game crashes at 22 textures
+ I_Error("Sector with more than 22 adjoining sectors. "
+ "Vanilla will crash here");
+ }
- // Check for overflow. Exit.
- if ( h >= MAX_ADJOINING_SECTORS )
- {
- fprintf( stderr,
- "Sector with more than 20 adjoining sectors\n" );
- break;
- }
+ heightlist[h++] = other->floorheight;
+ }
}
// Find lowest height in list
if (!h)
- return currentheight;
-
+ {
+ return currentheight;
+ }
+
min = heightlist[0];
// Range checking?
- for (i = 1;i < h;i++)
- if (heightlist[i] < min)
- min = heightlist[i];
-
+ for (i = 1; i < h; i++)
+ {
+ if (heightlist[i] < min)
+ {
+ min = heightlist[i];
+ }
+ }
+
return min;
}
-
//
// FIND LOWEST CEILING IN THE SURROUNDING SECTORS