diff --git a/src/p_setup.c b/src/p_setup.c index b36bf0b80..6c14e3614 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1931,10 +1931,18 @@ static void P_GroupLines(void) // allocate linebuffers for each sector for (i = 0, sector = sectors; i < numsectors; i++, sector++) { - sector->lines = Z_Calloc(sector->linecount * sizeof(line_t*), PU_LEVEL, NULL); + if (sector->linecount == 0) // no lines found? + { + sector->lines = NULL; + CONS_Debug(DBG_SETUP, "P_GroupLines: sector %d has no lines\n", i); + } + else + { + sector->lines = Z_Calloc(sector->linecount * sizeof(line_t*), PU_LEVEL, NULL); - // zero the count, since we'll later use this to track how many we've recorded - sector->linecount = 0; + // zero the count, since we'll later use this to track how many we've recorded + sector->linecount = 0; + } } // iterate through lines, assigning them to sectors' linebuffers, @@ -1952,11 +1960,14 @@ static void P_GroupLines(void) { M_ClearBox(bbox); - for (j = 0; j < sector->linecount; j++) + if (sector->linecount != 0) { - li = sector->lines[j]; - M_AddToBox(bbox, li->v1->x, li->v1->y); - M_AddToBox(bbox, li->v2->x, li->v2->y); + for (j = 0; j < sector->linecount; j++) + { + li = sector->lines[j]; + M_AddToBox(bbox, li->v1->x, li->v1->y); + M_AddToBox(bbox, li->v2->x, li->v2->y); + } } // set the degenmobj_t to the middle of the bounding box @@ -1966,6 +1977,35 @@ 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\0\0", 8) != 0) + { + rejectmatrix = NULL; + CONS_Debug(DBG_SETUP, "P_LoadReject: No valid REJECT lump found\n"); + return; + } + + count = W_LumpLength(lumpnum); + + if (!count) // zero length, someone probably used ZDBSP + { + rejectmatrix = NULL; + CONS_Debug(DBG_SETUP, "P_LoadReject: REJECT lump has size 0, will not be loaded\n"); + } + else + rejectmatrix = W_CacheLumpNum(lumpnum, PU_LEVEL); +} + #if 0 static char *levellumps[] = { @@ -2574,7 +2614,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