From c60227514289cd7d512539785bb2fe47d30db51a Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Thu, 24 Jun 2010 11:28:00 +0200 Subject: [PATCH] rnd-20100624-2-src * fixed another memory violation bug in the native Supaplex game engine (this potential memory bug was also in the original Megaplex code, but apparently only occured under rare conditions triggered by using the additional added preceding playfield memory area to make a few strange levels using dirty off-playfield tricks (bugs) like "12s033.sp" also solvable (this all worked fine in the classic DOS version, of course)) --- ChangeLog | 6 ++++++ src/conftime.h | 2 +- src/game_sp/Explosions.c | 2 +- src/game_sp/Globals.c | 12 +++++++++++- src/game_sp/Globals.h | 5 ++++- src/game_sp/file.c | 10 ++++++++++ src/game_sp/init.c | 2 ++ 7 files changed, 35 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index f8da0e50..c2872eed 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2010-06-24 * started adding alternative (smaller) tile size option for playing game + * fixed another memory violation bug in the native Supaplex game engine + (this potential memory bug was also in the original Megaplex code, but + apparently only occured under rare conditions triggered by using the + additional added preceding playfield memory area to make a few strange + levels using dirty off-playfield tricks (bugs) like "12s033.sp" also + solvable (this all worked fine in the classic DOS version, of course)) 2010-06-23 * added graphics performance optimization to native Supaplex game engine diff --git a/src/conftime.h b/src/conftime.h index c706413c..604c7cfb 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "2010-06-24 01:23" +#define COMPILE_DATE_STRING "2010-06-24 11:02" diff --git a/src/game_sp/Explosions.c b/src/game_sp/Explosions.c index 4eded7b3..867cc273 100644 --- a/src/game_sp/Explosions.c +++ b/src/game_sp/Explosions.c @@ -136,7 +136,7 @@ static void LetExplodeFieldSP(int tsi, int cx, int dh) { int al; - if (tsi < (-FieldWidth)) + if (tsi < -FieldWidth) return; al = LowByte(PlayField16[tsi]); diff --git a/src/game_sp/Globals.c b/src/game_sp/Globals.c index 91c71517..35bf4d8a 100644 --- a/src/game_sp/Globals.c +++ b/src/game_sp/Globals.c @@ -14,12 +14,15 @@ int FieldWidth; // standard size = 60 int FieldHeight; // standard size = 24 int HeaderSize; // standard size = 96 int FieldMax, LevelMax; +#if 0 long FileMax; +#endif #if 1 int *PlayField16; +byte *PlayField8; // int PlayField16[SP_MAX_PLAYFIELD_SIZE + SP_HEADER_SIZE]; -byte PlayField8[SP_MAX_PLAYFIELD_SIZE + SP_HEADER_SIZE]; +// byte PlayField8[SP_MAX_PLAYFIELD_SIZE + SP_HEADER_SIZE]; byte DisPlayField[SP_MAX_PLAYFIELD_SIZE + SP_HEADER_SIZE]; #else int *PlayField16; @@ -178,11 +181,18 @@ void InitGlobals() bPlaying = False; menBorder = False; + /* add preceding playfield buffer (as large as preceding memory area) */ PlayField16 = checked_calloc((game_sp.preceding_buffer_size + SP_MAX_PLAYFIELD_SIZE + SP_HEADER_SIZE) * sizeof(int)); PlayField16 = &PlayField16[game_sp.preceding_buffer_size]; + /* add preceding playfield buffer (as large as one playfield row) */ + PlayField8 = checked_calloc((SP_MAX_PLAYFIELD_WIDTH + + SP_MAX_PLAYFIELD_SIZE + + SP_HEADER_SIZE) * sizeof(byte)); + PlayField8 = &PlayField8[SP_MAX_PLAYFIELD_WIDTH]; + #if 0 /* these defaults will be changed after reading a Supaplex level file */ PlayField8 = REDIM_1D(sizeof(byte), 0, FieldMax); diff --git a/src/game_sp/Globals.h b/src/game_sp/Globals.h index 4c8798d7..5de5b8c8 100644 --- a/src/game_sp/Globals.h +++ b/src/game_sp/Globals.h @@ -296,8 +296,9 @@ extern boolean menBorder; #if 1 extern int *PlayField16; +extern byte *PlayField8; // extern int PlayField16[SP_MAX_PLAYFIELD_SIZE + SP_HEADER_SIZE]; -extern byte PlayField8[SP_MAX_PLAYFIELD_SIZE + SP_HEADER_SIZE]; +// extern byte PlayField8[SP_MAX_PLAYFIELD_SIZE + SP_HEADER_SIZE]; extern byte DisPlayField[SP_MAX_PLAYFIELD_SIZE + SP_HEADER_SIZE]; #else extern int *PlayField16; @@ -313,7 +314,9 @@ extern int HeaderSize; extern int TimerVar; extern short RandomSeed; +#if 0 extern long FileMax; +#endif extern LevelInfoType LInfo; extern int ScrollMinX, ScrollMaxX, ScrollMinY, ScrollMaxY; diff --git a/src/game_sp/file.c b/src/game_sp/file.c index cb5413b0..27cb452a 100644 --- a/src/game_sp/file.c +++ b/src/game_sp/file.c @@ -72,8 +72,10 @@ void copyInternalEngineVars_SP() FieldMax = (FieldWidth * FieldHeight) + HeaderSize - 1; LevelMax = (FieldWidth * FieldHeight) - 1; +#if 0 /* (add one byte for the level number stored as first byte of demo data) */ FileMax = FieldMax + native_sp_level.demo.length + 1; +#endif #if 0 PlayField8 = REDIM_1D(sizeof(byte), 0, FileMax); @@ -81,6 +83,14 @@ void copyInternalEngineVars_SP() PlayField16 = REDIM_1D(sizeof(int), -game_sp.preceding_buffer_size, FieldMax); #endif + /* initialize preceding playfield buffer */ + for (i = -game_sp.preceding_buffer_size; i < 0; i++) + PlayField16[i] = 0; + + /* initialize preceding playfield buffer */ + for (i = -SP_MAX_PLAYFIELD_WIDTH; i < 0; i++) + PlayField8[i] = 0; + count = 0; for (i = 0; game_sp.preceding_buffer[i] != NULL; i++) { diff --git a/src/game_sp/init.c b/src/game_sp/init.c index 8c77d306..07bdb9d9 100644 --- a/src/game_sp/init.c +++ b/src/game_sp/init.c @@ -130,7 +130,9 @@ void SaveEngineSnapshotValues_SP() SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(FieldHeight)); SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(FieldMax)); SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(LevelMax)); +#if 0 SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(FileMax)); +#endif SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(TimerVar)); SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(RandomSeed)); -- 2.34.1