From a7a7a7ee6d6f3b89fd85046b9b66d0a711e1a88b Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 11 Jun 2016 18:45:56 +0100 Subject: [PATCH] Added P_LoadReject function to properly check if REJECT lump is valid or not when loading it, so P_CheckSight can avoid accessing it if not. This should mean that maps built with ZBSDP (no reject) should have less or no problems in netgames compared to the standard ZenNode maps now, hopefully. =) --- src/p_setup.c | 27 ++++++++++++++++++++++++++- src/p_sight.c | 9 ++++++--- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index 0beb3be30..087ca6332 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1977,6 +1977,31 @@ static void P_GroupLines(void) } } +// +// P_LoadReject +// +// Detect if the REJECT lump is valid, +// if not, rejectmatrix will be NULL +static void P_LoadReject(lumpnum_t lumpnum) +{ + size_t count; + const char *lumpname = W_CheckNameForNum(lumpnum); + + // Check if the lump exists, and if it's named "REJECT" + if (!lumpname || memcmp(lumpname, "REJECT", 8) != 0) + { + rejectmatrix = NULL; + return; + } + + count = W_LumpLength(lumpnum); + + if (!count) // zero length, someone probably used ZDBSP + rejectmatrix = NULL; + else + rejectmatrix = W_CacheLumpNum(lumpnum, PU_LEVEL); +} + #if 0 static char *levellumps[] = { @@ -2585,7 +2610,7 @@ boolean P_SetupLevel(boolean skipprecip) P_LoadSubsectors(lastloadedmaplumpnum + ML_SSECTORS); P_LoadNodes(lastloadedmaplumpnum + ML_NODES); P_LoadSegs(lastloadedmaplumpnum + ML_SEGS); - rejectmatrix = W_CacheLumpNum(lastloadedmaplumpnum + ML_REJECT, PU_LEVEL); + P_LoadReject(lastloadedmaplumpnum + ML_REJECT); P_GroupLines(); numdmstarts = numredctfstarts = numbluectfstarts = 0; diff --git a/src/p_sight.c b/src/p_sight.c index 14c1c945f..bd6ab4d73 100644 --- a/src/p_sight.c +++ b/src/p_sight.c @@ -325,9 +325,12 @@ boolean P_CheckSight(mobj_t *t1, mobj_t *t2) s2 = t2->subsector->sector; pnum = (s1-sectors)*numsectors + (s2-sectors); - // Check in REJECT table. - if (rejectmatrix[pnum>>3] & (1 << (pnum&7))) // can't possibly be connected - return false; + if (rejectmatrix != NULL) + { + // Check in REJECT table. + if (rejectmatrix[pnum>>3] & (1 << (pnum&7))) // can't possibly be connected + return false; + } // killough 11/98: shortcut for melee situations // same subsector? obviously visible