From df92dc8d9ea84a58f66ba1d6c187d6d4ebeecbc4 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 11 Jun 2016 16:14:08 +0100 Subject: [PATCH 1/6] Print debugging message if sector->linecount is zero --- src/p_setup.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index b36bf0b80..0beb3be30 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 From a7a7a7ee6d6f3b89fd85046b9b66d0a711e1a88b Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 11 Jun 2016 18:45:56 +0100 Subject: [PATCH 2/6] 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 From 1d0e74f9c0c268bb37b2e2375b1fac0529687ea9 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 11 Jun 2016 21:19:16 +0100 Subject: [PATCH 3/6] "REJECT" is only 5 chars long, not 8. --- src/p_setup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_setup.c b/src/p_setup.c index 087ca6332..d7d169e6b 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1988,7 +1988,7 @@ static void P_LoadReject(lumpnum_t lumpnum) const char *lumpname = W_CheckNameForNum(lumpnum); // Check if the lump exists, and if it's named "REJECT" - if (!lumpname || memcmp(lumpname, "REJECT", 8) != 0) + if (!lumpname || memcmp(lumpname, "REJECT", 5) != 0) { rejectmatrix = NULL; return; From 472dce1ae65df01972acda0e13d3d00e629a3508 Mon Sep 17 00:00:00 2001 From: Alam Ed Arias Date: Sat, 11 Jun 2016 21:42:02 -0400 Subject: [PATCH 4/6] Do not why we are not checking REJECT\0\0, let fix this check --- src/p_setup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_setup.c b/src/p_setup.c index d7d169e6b..755f32a85 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1988,7 +1988,7 @@ static void P_LoadReject(lumpnum_t lumpnum) const char *lumpname = W_CheckNameForNum(lumpnum); // Check if the lump exists, and if it's named "REJECT" - if (!lumpname || memcmp(lumpname, "REJECT", 5) != 0) + if (!lumpname || memcmp(lumpname, "REJECT", 7) != 0) { rejectmatrix = NULL; return; From f94dd510adb882147528c150d5fdd682ec27fdb6 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sun, 12 Jun 2016 21:16:41 +0100 Subject: [PATCH 5/6] change back to 8, add \0s --- src/p_setup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_setup.c b/src/p_setup.c index 755f32a85..8dcfa6d91 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1988,7 +1988,7 @@ static void P_LoadReject(lumpnum_t lumpnum) const char *lumpname = W_CheckNameForNum(lumpnum); // Check if the lump exists, and if it's named "REJECT" - if (!lumpname || memcmp(lumpname, "REJECT", 7) != 0) + if (!lumpname || memcmp(lumpname, "REJECT\0\0", 8) != 0) { rejectmatrix = NULL; return; From 9b037164bcef8410a006ab3d44dbda97303b6ceb Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sun, 12 Jun 2016 21:51:27 +0100 Subject: [PATCH 6/6] Added debug messages for when REJECT lump is not loaded --- src/p_setup.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/p_setup.c b/src/p_setup.c index 8dcfa6d91..6c14e3614 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1991,13 +1991,17 @@ static void P_LoadReject(lumpnum_t lumpnum) 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); }