From af89c2515100a5c9d7add02b1f1067aab270ad46 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 21 May 2022 13:57:47 +0200 Subject: [PATCH] - RR: clear jaildoors array on map start. this was leaving stale data behind which could cause nasty crashes. --- source/core/savegamehelp.h | 5 +++-- source/games/duke/src/actors_lava.cpp | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/source/core/savegamehelp.h b/source/core/savegamehelp.h index c71503020..e19d10e4f 100644 --- a/source/core/savegamehelp.h +++ b/source/core/savegamehelp.h @@ -24,9 +24,10 @@ void M_Autosave(); template<> inline FSerializer& Serialize(FSerializer& arc, const char* keyname, sectortype*& w, sectortype** def) { + assert(arc.isReading() || w == nullptr || (w >= §or[0] && w <= §or.Last())); int ndx = w ? sectnum(w) : -1; arc(keyname, ndx); - w = ndx == -1 ? nullptr : §or[ndx]; + w = !validSectorIndex(ndx) ? nullptr : §or[ndx]; return arc; } @@ -34,7 +35,7 @@ template<> inline FSerializer& Serialize(FSerializer& arc, const char* keyname, { int ndx = w ? wallnum(w) : -1; arc(keyname, ndx); - w = ndx == -1 ? nullptr : &wall[ndx]; + w = !validWallIndex(ndx) ? nullptr : &wall[ndx]; return arc; } diff --git a/source/games/duke/src/actors_lava.cpp b/source/games/duke/src/actors_lava.cpp index f7faf5075..e8c3f1666 100644 --- a/source/games/duke/src/actors_lava.cpp +++ b/source/games/duke/src/actors_lava.cpp @@ -36,7 +36,6 @@ Prepared for public release: 03/21/2003 - Charlie Wiederhold, 3D Realms BEGIN_DUKE_NS static int torchcnt; -static int jaildoorcnt; static int lightnincnt; static sectortype* torchsector[64]; @@ -84,7 +83,7 @@ static int windertime; void lava_cleararrays() { - jaildoorcnt = 0; + jaildoors.Clear(); minecarts.Clear(); torchcnt = 0; lightnincnt = 0; @@ -274,6 +273,7 @@ void dojaildoor(void) for(auto& jd : jaildoors) { auto sectp = jd.sect; + if (!sectp) continue; // this is only for allowing old, broken savegames to work, this would crash otherwise. double speed = max(2, jd.speed) * maptoworld; if (jd.open == 1 || jd.open == 3)