- RR: clear jaildoors array on map start.

this was leaving stale data behind which could cause nasty crashes.
This commit is contained in:
Christoph Oelckers 2022-05-21 13:57:47 +02:00
parent 79c671b890
commit af89c25151
2 changed files with 5 additions and 4 deletions

View file

@ -24,9 +24,10 @@ void M_Autosave();
template<> inline FSerializer& Serialize(FSerializer& arc, const char* keyname, sectortype*& w, sectortype** def) template<> inline FSerializer& Serialize(FSerializer& arc, const char* keyname, sectortype*& w, sectortype** def)
{ {
assert(arc.isReading() || w == nullptr || (w >= &sector[0] && w <= &sector.Last()));
int ndx = w ? sectnum(w) : -1; int ndx = w ? sectnum(w) : -1;
arc(keyname, ndx); arc(keyname, ndx);
w = ndx == -1 ? nullptr : &sector[ndx]; w = !validSectorIndex(ndx) ? nullptr : &sector[ndx];
return arc; return arc;
} }
@ -34,7 +35,7 @@ template<> inline FSerializer& Serialize(FSerializer& arc, const char* keyname,
{ {
int ndx = w ? wallnum(w) : -1; int ndx = w ? wallnum(w) : -1;
arc(keyname, ndx); arc(keyname, ndx);
w = ndx == -1 ? nullptr : &wall[ndx]; w = !validWallIndex(ndx) ? nullptr : &wall[ndx];
return arc; return arc;
} }

View file

@ -36,7 +36,6 @@ Prepared for public release: 03/21/2003 - Charlie Wiederhold, 3D Realms
BEGIN_DUKE_NS BEGIN_DUKE_NS
static int torchcnt; static int torchcnt;
static int jaildoorcnt;
static int lightnincnt; static int lightnincnt;
static sectortype* torchsector[64]; static sectortype* torchsector[64];
@ -84,7 +83,7 @@ static int windertime;
void lava_cleararrays() void lava_cleararrays()
{ {
jaildoorcnt = 0; jaildoors.Clear();
minecarts.Clear(); minecarts.Clear();
torchcnt = 0; torchcnt = 0;
lightnincnt = 0; lightnincnt = 0;
@ -274,6 +273,7 @@ void dojaildoor(void)
for(auto& jd : jaildoors) for(auto& jd : jaildoors)
{ {
auto sectp = jd.sect; 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; double speed = max(2, jd.speed) * maptoworld;
if (jd.open == 1 || jd.open == 3) if (jd.open == 1 || jd.open == 3)