From d8ffffd86eca133c575af291ba08f86aeaaec576 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 22 Jun 2026 20:52:11 +0200 Subject: [PATCH 1/5] replace non valid sidenum magic number with what dsda-doom uses --- src/doomdata.h | 4 +++- src/hardware/hw_bsp.c | 2 +- src/hardware/hw_cache.c | 2 +- src/lua_maplib.c | 2 +- src/p_maputl.cpp | 4 ++-- src/p_saveg.c | 10 ++++++---- src/p_setup.c | 20 ++++++++++---------- src/p_spec.c | 18 +++++++++--------- src/r_defs.h | 2 +- src/r_segs.cpp | 2 +- src/r_splats.c | 2 +- 11 files changed, 36 insertions(+), 32 deletions(-) diff --git a/src/doomdata.h b/src/doomdata.h index 2f5e014c7..77dd84c50 100644 --- a/src/doomdata.h +++ b/src/doomdata.h @@ -81,10 +81,12 @@ typedef struct INT16 flags; INT16 special; INT16 tag; - // sidenum[1] will be 0xffff if one sided + // sidenum[1] will be NO_INDEX if one sided UINT16 sidenum[2]; } ATTRPACK maplinedef_t; +#define NO_INDEX 0xffff + // // LineDef attributes. // diff --git a/src/hardware/hw_bsp.c b/src/hardware/hw_bsp.c index 79069857c..77f66d308 100644 --- a/src/hardware/hw_bsp.c +++ b/src/hardware/hw_bsp.c @@ -373,7 +373,7 @@ static poly_t *CutOutSubsecPoly(seg_t *lseg, INT32 count, poly_t *poly) if (!gl_maphashorizonlines && line->special == HORIZONSPECIAL) gl_maphashorizonlines = true; - if (line->sidenum[1] != 0xffff) + if (line->sidenum[1] != NO_INDEX) { if (sides[line->sidenum[0]].sector == sides[line->sidenum[1]].sector) { diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index d7c25bf3d..9300cbe81 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -729,7 +729,7 @@ static void HWR_PrecacheLevelTextures(void) for (j = 0; j < 2; j++) { // check if single-sided linedef - if (line->sidenum[j] == 0xffff) + if (line->sidenum[j] == NO_INDEX) continue; const side_t *side = &sides[line->sidenum[j]]; diff --git a/src/lua_maplib.c b/src/lua_maplib.c index 279b02883..87639b77b 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -652,7 +652,7 @@ static int line_get(lua_State *L) LUA_PushUserdata(L, &sides[line->sidenum[0]], META_SIDE); return 1; case line_backside: // backside - if (line->sidenum[1] == 0xffff) + if (line->sidenum[1] == NO_INDEX) return 0; LUA_PushUserdata(L, &sides[line->sidenum[1]], META_SIDE); return 1; diff --git a/src/p_maputl.cpp b/src/p_maputl.cpp index 38e350409..d9f22c28a 100644 --- a/src/p_maputl.cpp +++ b/src/p_maputl.cpp @@ -242,7 +242,7 @@ void P_CameraLineOpening(line_t *linedef) sector_t *back; fixed_t frontfloor, frontceiling, backfloor, backceiling; - if (linedef->sidenum[1] == 0xffff) + if (linedef->sidenum[1] == NO_INDEX) { // single sided line openrange = 0; @@ -398,7 +398,7 @@ void P_LineOpening(line_t *linedef, mobj_t *mobj) { sector_t *front, *back; - if (linedef->sidenum[1] == 0xffff) + if (linedef->sidenum[1] == NO_INDEX) { // single sided line openrange = 0; diff --git a/src/p_saveg.c b/src/p_saveg.c index 667ee5c47..0d8ebd713 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -691,7 +691,7 @@ static void ArchiveLines(savebuffer_t *save) if (spawnli->special == 321 || spawnli->special == 322) // only reason li->callcount would be non-zero is if either of these are involved diff |= LD_CLLCOUNT; - if (li->sidenum[0] != 0xffff) + if (li->sidenum[0] != NO_INDEX) { si = &sides[li->sidenum[0]]; spawnsi = &spawnsides[li->sidenum[0]]; @@ -706,7 +706,8 @@ static void ArchiveLines(savebuffer_t *save) if (si->midtexture != spawnsi->midtexture) diff |= LD_S1MIDTEX; } - if (li->sidenum[1] != 0xffff) + + if (li->sidenum[1] != NO_INDEX) { si = &sides[li->sidenum[1]]; spawnsi = &spawnsides[li->sidenum[1]]; @@ -786,6 +787,7 @@ static void UnArchiveFFloors(savebuffer_t *save, const sector_t *ss) I_Error("Sector does not have any ffloors!"); fflr_i = READUINT16(save->p); // get first modified ffloor's number ready + for (;;) // for some reason the usual for (rover = x; ...) thing doesn't work here? { if (fflr_i == 0xffff) // end of modified ffloors list, let's stop already @@ -3510,7 +3512,7 @@ static void P_ReloadSaveLevelData(void) li->firsttag = spawnli->firsttag; li->nexttag = spawnli->nexttag; - if (li->sidenum[0] != 0xffff) + if (li->sidenum[0] != NO_INDEX) { si = &sides[li->sidenum[0]]; spawnsi = &spawnsides[li->sidenum[0]]; @@ -3521,7 +3523,7 @@ static void P_ReloadSaveLevelData(void) si->midtexture = spawnsi->midtexture; } - if (li->sidenum[1] != 0xffff) + if (li->sidenum[1] != NO_INDEX) { si = &sides[li->sidenum[1]]; spawnsi = &spawnsides[li->sidenum[1]]; diff --git a/src/p_setup.c b/src/p_setup.c index aee747626..3af2324a3 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1001,9 +1001,9 @@ static void P_InitializeLinedef(line_t *ld) // cph 2002/07/20 - these errors are fatal if not fixed, so apply them for (j = 0; j < 2; j++) { - if (ld->sidenum[j] != 0xffff && ld->sidenum[j] >= (UINT16)numsides) + if (ld->sidenum[j] != NO_INDEX && ld->sidenum[j] >= (UINT16)numsides) { - ld->sidenum[j] = 0xffff; + ld->sidenum[j] = NO_INDEX; CONS_Debug(DBG_SETUP, "P_InitializeLinedef: Linedef %s has out-of-range sidedef number\n", sizeu1((size_t)(ld - lines))); } } @@ -1011,14 +1011,14 @@ static void P_InitializeLinedef(line_t *ld) ld->firsttag = ld->nexttag = -1; // killough 11/98: fix common wad errors (missing sidedefs): - if (ld->sidenum[0] == 0xffff) + if (ld->sidenum[0] == NO_INDEX) { ld->sidenum[0] = 0; // Substitute dummy sidedef for missing right side // cph - print a warning about the bug CONS_Debug(DBG_SETUP, "P_InitializeLinedef: Linedef %s missing first sidedef\n", sizeu1((size_t)(ld - lines))); } - if ((ld->sidenum[1] == 0xffff) && (ld->flags & ML_TWOSIDED)) + if ((ld->sidenum[1] == NO_INDEX) && (ld->flags & ML_TWOSIDED)) { ld->flags &= ~ML_TWOSIDED; // Clear 2s flag for missing left side // cph - print a warning about the bug @@ -1026,9 +1026,9 @@ static void P_InitializeLinedef(line_t *ld) } // killough 4/4/98: support special sidedef interpretation below - if (ld->sidenum[0] != 0xffff && ld->special) + if (ld->sidenum[0] != NO_INDEX && ld->special) sides[ld->sidenum[0]].special = ld->special; - if (ld->sidenum[1] != 0xffff && ld->special) + if (ld->sidenum[1] != NO_INDEX && ld->special) sides[ld->sidenum[1]].special = ld->special; } @@ -1061,10 +1061,10 @@ static void P_LoadLineDefs2(void) for (; i--; ld++) { ld->frontsector = sides[ld->sidenum[0]].sector; //e6y: Can't be -1 here - ld->backsector = ld->sidenum[1] != 0xffff ? sides[ld->sidenum[1]].sector : NULL; + ld->backsector = ld->sidenum[1] != NO_INDEX ? sides[ld->sidenum[1]].sector : NULL; // Repeat count for midtexture - if ((ld->flags & ML_EFFECT5) && (ld->sidenum[1] != 0xffff)) + if ((ld->flags & ML_EFFECT5) && (ld->sidenum[1] != NO_INDEX)) { sides[ld->sidenum[0]].repeatcnt = (INT16)(((unsigned)sides[ld->sidenum[0]].textureoffset >> FRACBITS) >> 12); sides[ld->sidenum[0]].textureoffset = (((unsigned)sides[ld->sidenum[0]].textureoffset >> FRACBITS) & 2047) << FRACBITS; @@ -1080,13 +1080,13 @@ static void P_LoadLineDefs2(void) { size_t len = strlen(sides[ld->sidenum[0]].text)+1; - if (ld->sidenum[1] != 0xffff && sides[ld->sidenum[1]].text) + if (ld->sidenum[1] != NO_INDEX && sides[ld->sidenum[1]].text) len += strlen(sides[ld->sidenum[1]].text); ld->text = Z_Malloc(len, PU_LEVEL, NULL); memcpy(ld->text, sides[ld->sidenum[0]].text, strlen(sides[ld->sidenum[0]].text)+1); - if (ld->sidenum[1] != 0xffff && sides[ld->sidenum[1]].text) + if (ld->sidenum[1] != NO_INDEX && sides[ld->sidenum[1]].text) memcpy(ld->text+strlen(ld->text)+1, sides[ld->sidenum[1]].text, strlen(sides[ld->sidenum[1]].text)+1); } break; diff --git a/src/p_spec.c b/src/p_spec.c index 978c3041e..032fdbfbd 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -889,7 +889,7 @@ static boolean PolyDoor(line_t *line) pdd.angle = line->angle; // angle of motion pdd.distance = sides[line->sidenum[0]].rowoffset; - if (line->sidenum[1] != 0xffff) + if (line->sidenum[1] != NO_INDEX) pdd.delay = sides[line->sidenum[1]].textureoffset >> FRACBITS; // delay in tics else pdd.delay = 0; @@ -899,7 +899,7 @@ static boolean PolyDoor(line_t *line) pdd.speed = sides[line->sidenum[0]].textureoffset >> FRACBITS; // angular speed pdd.distance = sides[line->sidenum[0]].rowoffset >> FRACBITS; // angular distance - if (line->sidenum[1] != 0xffff) + if (line->sidenum[1] != NO_INDEX) pdd.delay = sides[line->sidenum[1]].textureoffset >> FRACBITS; // delay in tics else pdd.delay = 0; @@ -1989,8 +1989,8 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) INT32 position = (INT32)max(sides[line->sidenum[0]].midtexture, 0); UINT32 prefadems = (UINT32)max(sides[line->sidenum[0]].textureoffset >> FRACBITS, 0); UINT32 postfadems = (UINT32)max(sides[line->sidenum[0]].rowoffset >> FRACBITS, 0); - UINT8 fadetarget = (UINT8)max((line->sidenum[1] != 0xffff) ? sides[line->sidenum[1]].textureoffset >> FRACBITS : 0, 0); - INT16 fadesource = (INT16)max((line->sidenum[1] != 0xffff) ? sides[line->sidenum[1]].rowoffset >> FRACBITS : -1, -1); + UINT8 fadetarget = (UINT8)max((line->sidenum[1] != NO_INDEX) ? sides[line->sidenum[1]].textureoffset >> FRACBITS : 0, 0); + INT16 fadesource = (INT16)max((line->sidenum[1] != NO_INDEX) ? sides[line->sidenum[1]].rowoffset >> FRACBITS : -1, -1); // Seek offset from current song position if (line->flags & ML_EFFECT1) @@ -2504,7 +2504,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) var1 = sides[line->sidenum[0]].toptexture; //(line->dx>>FRACBITS)-1; - if (line->sidenum[1] != 0xffff && line->flags & ML_BLOCKMONSTERS) // read power from back sidedef + if (line->sidenum[1] != NO_INDEX && line->flags & ML_BLOCKMONSTERS) // read power from back sidedef var2 = sides[line->sidenum[1]].toptexture; else if (line->flags & ML_NOCLIMB) // 'Infinite' var2 = UINT16_MAX; @@ -2633,7 +2633,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) if (always || this->bottomtexture) this->bottomtexture = set->bottomtexture; - if (lines[linenum].sidenum[1] == 0xffff) + if (lines[linenum].sidenum[1] == NO_INDEX) continue; // One-sided stops here. // Back side @@ -2682,7 +2682,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) sector_t *sec; mobj_t *thing; - if (line->sidenum[1] != 0xffff) + if (line->sidenum[1] != NO_INDEX) state = (statenum_t)sides[line->sidenum[1]].toptexture; while ((secnum = P_FindSectorFromLineTag(line, secnum)) >= 0) @@ -6056,7 +6056,7 @@ void P_SpawnSpecials(INT32 fromnetsave, boolean reloadinggamestate) break; case 259: // Make-Your-Own FOF! - if (lines[i].sidenum[1] != 0xffff) + if (lines[i].sidenum[1] != NO_INDEX) { UINT8 *data; UINT16 b; @@ -6785,7 +6785,7 @@ static void P_SpawnScrollers(void) case 506: s = lines[i].sidenum[1]; - if (s != 0xffff) + if (s != NO_INDEX) Add_Scroller(sc_side, -sides[s].textureoffset, sides[s].rowoffset, -1, lines[i].sidenum[0], accel, 0); else CONS_Debug(DBG_GAMELOGIC, "Line special 506 (line #%s) missing 2nd side!\n", sizeu1(i)); diff --git a/src/r_defs.h b/src/r_defs.h index 217314028..680a8a9cc 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -430,7 +430,7 @@ typedef struct line_s INT16 tag; // Visual appearance: sidedefs. - UINT16 sidenum[2]; // sidenum[1] will be 0xffff if one-sided + UINT16 sidenum[2]; // sidenum[1] will be NO_INDEX if one-sided fixed_t alpha; // translucency UINT8 blendmode; // blendmode diff --git a/src/r_segs.cpp b/src/r_segs.cpp index 26e5a582b..8460d4679 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -2206,7 +2206,7 @@ void R_StoreWallRange(INT32 start, INT32 stop) topremap = (encoremap && !(curline->linedef->flags & ML_TFERLINE)); if ((linedef->flags & (ML_DONTPEGTOP) && (linedef->flags & ML_DONTPEGBOTTOM)) - && linedef->sidenum[1] != 0xffff) + && linedef->sidenum[1] != NO_INDEX) { // Special case... use offsets from 2nd side but only if it has a texture. side_t *def = &sides[linedef->sidenum[1]]; diff --git a/src/r_splats.c b/src/r_splats.c index bcef8cf24..5560477ba 100644 --- a/src/r_splats.c +++ b/src/r_splats.c @@ -131,7 +131,7 @@ void R_AddWallSplat(line_t *wallline, INT16 sectorside, const char *patchname, f // set the splat splat->patch = W_GetNumForName(patchname); sectorside ^= 1; - if (wallline->sidenum[sectorside] != 0xffff) + if (wallline->sidenum[sectorside] != NO_INDEX) { backsector = sides[wallline->sidenum[sectorside]].sector; From 363612c488a4971efb56832e628b91c91b63db5f Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 19 Jun 2026 16:52:33 +0200 Subject: [PATCH 2/5] port more checks from dsda-doom for invalid map data decided to have it i_error for now, not sure what exactly is the best approach here should we just "correct" some of those instead? vanilla probably just crashes anyways --- src/p_setup.c | 130 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 124 insertions(+), 6 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index 3af2324a3..a5769179c 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -437,8 +437,41 @@ static void P_LoadSegs(UINT8 *data) for (i = 0; i < numsegs; i++, li++, ml++) { - li->v1 = &vertexes[SHORT(ml->v1)]; - li->v2 = &vertexes[SHORT(ml->v2)]; + INT16 v1, v2; + + v1 = SHORT(ml->v1); + v2 = SHORT(ml->v2); + + // e6y + // check and fix wrong references to non-existent vertexes + // see e1m9 @ NIVELES.WAD + // http://www.doomworld.com/idgames/index.php?id=12647 + if ((unsigned)v1 >= numvertexes || (unsigned)v2 >= numvertexes) + { + if ((unsigned)v1 >= numvertexes) + I_Error("P_LoadSegs: seg %s references a non-existent vertex %d\n", sizeu1(i), v1); + if ((unsigned)v2 >= numvertexes) + I_Error("P_LoadSegs: seg %s references a non-existent vertex %d\n", sizeu1(i), v2); + + /* + if (li->sidedef == &sides[li->linedef->sidenum[0]]) + { + li->v1 = lines[ml->linedef].v1; + li->v2 = lines[ml->linedef].v2; + } + else + { + li->v1 = lines[ml->linedef].v2; + li->v2 = lines[ml->linedef].v1; + } + */ + } + else + { + li->v1 = &vertexes[v1]; + li->v2 = &vertexes[v2]; + } + #ifdef HWRENDER if (rendermode == render_opengl) { @@ -455,14 +488,60 @@ static void P_LoadSegs(UINT8 *data) li->angle = (SHORT(ml->angle))<offset = (SHORT(ml->offset))<linedef); + + //e6y: check for wrong indexes + if ((unsigned)rawlinedef >= numlines) + { + I_Error("P_LoadSegs: seg %s references a non-existent linedef %d", sizeu1(i), (unsigned)rawlinedef); + } + ldef = &lines[rawlinedef]; li->linedef = ldef; - li->side = rawside = SHORT(ml->side); + rawside = SHORT(ml->side); + + //e6y: fix wrong side index + if (rawside != 0 && rawside != 1) + { + I_Error("P_LoadSegs: seg %s contains wrong side index %d.\n", sizeu1(i), rawside); + //rawside = 1; + } + + //e6y: check for wrong indexes + if (ldef->sidenum[rawside] >= numsides) + { + I_Error("P_LoadSegs: linedef %d for seg %s references a non-existent sidedef %d", rawlinedef, sizeu1(i), ldef->sidenum[rawside]); + } + + li->side = rawside; + li->sidedef = &sides[ldef->sidenum[rawside]]; - li->frontsector = sides[ldef->sidenum[rawside]].sector; + + /* cph 2006/09/30 - our frontsector can be the second side of the + * linedef, so must check for NO_INDEX in case we are incorrectly + * referencing the back of a 1S line */ + if (ldef->sidenum[rawside] == NO_INDEX) + { + I_Error("P_LoadSegs: front of seg %s has no sidedef\n", sizeu1(i)); + //li->frontsector = 0; + } + else + { + li->frontsector = sides[ldef->sidenum[rawside]].sector; + } if (ldef->flags & ML_TWOSIDED) - li->backsector = sides[ldef->sidenum[rawside^1]].sector; + { + if (ldef->sidenum[rawside^1] == NO_INDEX) + { + I_Error("P_LoadSegs: back of seg %s has no sidedef while being marked as double sided\n", sizeu1(i)); + // this is wrong + //li->backsector = GetSectorAtNullAddress(); + } + else + { + li->backsector = sides[ldef->sidenum[rawside^1]].sector; + } + } P_UpdateSegLightOffset(li); } @@ -738,7 +817,33 @@ static void P_LoadNodes(UINT8 *data) for (j = 0; j < 2; j++) { - no->children[j] = SHORT(mn->children[j]); + UINT16 child; + + child = SHORT(mn->children[j]); + + if (child & NF_SUBSECTOR) + { + // Convert to extended type + child &= ~NF_SUBSECTOR; + + // haleyjd 11/06/10: check for invalid subsector reference + if (child >= numsubsectors) + { + I_Error("P_LoadNodes: BSP tree %s references invalid subsector %d\n", sizeu1(i), child); + //child = 0; + } + + child |= NF_SUBSECTOR; + } + else if (child >= numnodes) + { + I_Error("P_LoadNodes: BSP node %s references invalid node.\n", sizeu1(i)); + //I_Error("P_LoadNodes: BSP node %d references invalid node %d.\n", sizeu1(i), Index(((node_t *)no->children[j]))); + //child = 0; + } + + no->children[j] = child; + for (k = 0; k < 4; k++) no->bbox[j][k] = SHORT(mn->bbox[j][k])<firstline >= numsegs) + { CorruptMapError(va("P_GroupLines: ss->firstline invalid " "(subsector %s, firstline refers to %d of %s)", sizeu1(i), ss->firstline, sizeu2(numsegs))); + } + seg = &segs[ss->firstline]; sidei = (size_t)(seg->sidedef - sides); + if (!seg->sidedef) + { CorruptMapError(va("P_GroupLines: seg->sidedef is NULL " "(subsector %s, firstline is %d)", sizeu1(i), ss->firstline)); + } + if (seg->sidedef - sides < 0 || seg->sidedef - sides > (UINT16)numsides) + { CorruptMapError(va("P_GroupLines: seg->sidedef refers to sidedef %s of %s " "(subsector %s, firstline is %d)", sizeu1(sidei), sizeu2(numsides), sizeu3(i), ss->firstline)); + } + if (!seg->sidedef->sector) + { CorruptMapError(va("P_GroupLines: seg->sidedef->sector is NULL " "(subsector %s, firstline is %d, sidedef is %s)", sizeu1(i), ss->firstline, sizeu1(sidei))); + } + ss->sector = seg->sidedef->sector; } From 2dacc333b5ffa4cd601e89b6182e9e0382c84396 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 22 Jun 2026 20:52:42 +0200 Subject: [PATCH 3/5] just set backsector to NULL if not in vanilla doom compat mode/overflow emulation GetSectorAtNullAddress will just return NULL, so we can do so aswell --- src/p_setup.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index a5769179c..a7435c0c4 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -534,8 +534,7 @@ static void P_LoadSegs(UINT8 *data) if (ldef->sidenum[rawside^1] == NO_INDEX) { I_Error("P_LoadSegs: back of seg %s has no sidedef while being marked as double sided\n", sizeu1(i)); - // this is wrong - //li->backsector = GetSectorAtNullAddress(); + li->backsector = NULL; } else { From 568f29ed1c6fb44204131e1878b1da7d965c9209 Mon Sep 17 00:00:00 2001 From: entryway Date: Sat, 27 Mar 2010 19:34:43 +0000 Subject: [PATCH 4/5] Check for blockmap overflow in P_BlockLinesIterator. Under RANGECHECK define. --- src/p_maputl.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/p_maputl.cpp b/src/p_maputl.cpp index d9f22c28a..041bad1db 100644 --- a/src/p_maputl.cpp +++ b/src/p_maputl.cpp @@ -972,6 +972,10 @@ boolean P_BlockLinesIterator(INT32 x, INT32 y, boolean (*func)(line_t *)) // First index is really empty, so +1 it. for (list = blockmaplump + offset + 1; *list != -1; list++) { +#ifdef RANGECHECK + if (*list < 0 || (UINT32)*list >= numlines) + I_Error("P_BlockLinesIterator: index >= numlines"); +#endif ld = &lines[*list]; if (ld->validcount == validcount) From 029c21eae822953a961a7627ee259de10fa21846 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 22 Jun 2026 20:53:49 +0200 Subject: [PATCH 5/5] correct map issues clientside MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit but be loud about it instead of I_Error“ing most of those would be fatal anyways, so screw vanilla desyncing if they crash eitherways --- src/g_game.c | 3 ++ src/p_saveg.c | 3 ++ src/p_setup.c | 103 +++++++++++++++++++++++++++++++++++++------------- src/p_setup.h | 3 ++ 4 files changed, 85 insertions(+), 27 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index 22f811bc8..f720f98fd 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -1310,6 +1310,7 @@ static void G_DoLoadLevel(boolean resetplayer) { // fail so reset game stuff Command_ExitGame_f(); + P_FreeCorruptMapWarnings(); return; } @@ -1343,6 +1344,8 @@ static void G_DoLoadLevel(boolean resetplayer) // clear hud messages remains (usually from game startup) CON_ClearHUD(); + // print any map errors now due to clearhud above :chaosleep: + P_PrintCorruptMapWarnings(); server_lagless = !cv_gentlemens.value; diff --git a/src/p_saveg.c b/src/p_saveg.c index 0d8ebd713..37fcf4c3e 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -3590,8 +3590,11 @@ FUNCINLINE static ATTRINLINE boolean P_NetUnArchiveMisc(savebuffer_t *save, bool if (!P_SetupLevel(true, reloading)) { CONS_Alert(CONS_ERROR, M_GetText("Can't load the level!\n")); + P_FreeCorruptMapWarnings(); return false; } + + P_PrintCorruptMapWarnings(); } else { diff --git a/src/p_setup.c b/src/p_setup.c index a7435c0c4..c8edf26de 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -188,6 +188,57 @@ FUNCNORETURN static ATTRNORETURN void CorruptMapError(const char *msg) I_Error("Invalid or corrupt map.\nLook in log file or text console for technical details."); } +static char **mapwarnings = NULL; +static size_t nummapwarnings = 0; + +// collect map errors we can fix clientside +// we then can print em when the map finishes loading +// so they actually appear and raise awareness shits fucked +// see G_DoLoadLevel as to why :chaosleep: +static void CorruptMapWarning(const char *msg) +{ +#ifdef PARANOIA + // just error out + I_Error("%sThis WILL crash Vanilla clients!\n", msg); +#endif + nummapwarnings++; + mapwarnings = Z_Realloc(mapwarnings, nummapwarnings * sizeof(*mapwarnings), PU_STATIC, NULL); + mapwarnings[nummapwarnings-1] = Z_StrDup(msg); +} + +void P_PrintCorruptMapWarnings(void) +{ + size_t i; + + if (!nummapwarnings) + return; + + for (i = 0; i < nummapwarnings; i++) + { + CONS_Alert(CONS_ERROR, "%sAttempting to fix... This WILL crash Vanilla clients!\n", mapwarnings[i]); + } + + P_FreeCorruptMapWarnings(); +} + +void P_FreeCorruptMapWarnings(void) +{ + size_t i; + + if (!nummapwarnings) + return; + + for (i = 0; i < nummapwarnings; i++) + { + Z_Free(mapwarnings[i]); + mapwarnings[i] = NULL; + } + + Z_Free(mapwarnings); + mapwarnings = NULL; + nummapwarnings = 0; +} + #define NUMLAPS_DEFAULT 3 static void P_ClearMapHeaderLighting(mapheader_lighting_t *lighting) @@ -449,11 +500,10 @@ static void P_LoadSegs(UINT8 *data) if ((unsigned)v1 >= numvertexes || (unsigned)v2 >= numvertexes) { if ((unsigned)v1 >= numvertexes) - I_Error("P_LoadSegs: seg %s references a non-existent vertex %d\n", sizeu1(i), v1); + CorruptMapWarning(va("P_LoadSegs: seg %s references a non-existent vertex %d\n", sizeu1(i), v1)); if ((unsigned)v2 >= numvertexes) - I_Error("P_LoadSegs: seg %s references a non-existent vertex %d\n", sizeu1(i), v2); + CorruptMapWarning(va("P_LoadSegs: seg %s references a non-existent vertex %d\n", sizeu1(i), v2)); - /* if (li->sidedef == &sides[li->linedef->sidenum[0]]) { li->v1 = lines[ml->linedef].v1; @@ -464,7 +514,6 @@ static void P_LoadSegs(UINT8 *data) li->v1 = lines[ml->linedef].v2; li->v2 = lines[ml->linedef].v1; } - */ } else { @@ -502,8 +551,8 @@ static void P_LoadSegs(UINT8 *data) //e6y: fix wrong side index if (rawside != 0 && rawside != 1) { - I_Error("P_LoadSegs: seg %s contains wrong side index %d.\n", sizeu1(i), rawside); - //rawside = 1; + CorruptMapWarning(va("P_LoadSegs: seg %s contains wrong side index %d.\n", sizeu1(i), rawside)); + rawside = 1; } //e6y: check for wrong indexes @@ -521,8 +570,8 @@ static void P_LoadSegs(UINT8 *data) * referencing the back of a 1S line */ if (ldef->sidenum[rawside] == NO_INDEX) { - I_Error("P_LoadSegs: front of seg %s has no sidedef\n", sizeu1(i)); - //li->frontsector = 0; + CorruptMapWarning(va("P_LoadSegs: front of seg %s has no sidedef\n", sizeu1(i))); + li->frontsector = NULL; } else { @@ -533,7 +582,7 @@ static void P_LoadSegs(UINT8 *data) { if (ldef->sidenum[rawside^1] == NO_INDEX) { - I_Error("P_LoadSegs: back of seg %s has no sidedef while being marked as double sided\n", sizeu1(i)); + CorruptMapWarning(va("P_LoadSegs: back of seg %s has no sidedef while being marked as double sided\n", sizeu1(i))); li->backsector = NULL; } else @@ -828,17 +877,17 @@ static void P_LoadNodes(UINT8 *data) // haleyjd 11/06/10: check for invalid subsector reference if (child >= numsubsectors) { - I_Error("P_LoadNodes: BSP tree %s references invalid subsector %d\n", sizeu1(i), child); - //child = 0; + CorruptMapWarning(va("P_LoadNodes: BSP tree %s references invalid subsector %d\n", sizeu1(i), child)); + child = 0; } child |= NF_SUBSECTOR; } else if (child >= numnodes) { - I_Error("P_LoadNodes: BSP node %s references invalid node.\n", sizeu1(i)); + CorruptMapWarning(va("P_LoadNodes: BSP node %s references invalid node.\n", sizeu1(i))); //I_Error("P_LoadNodes: BSP node %d references invalid node %d.\n", sizeu1(i), Index(((node_t *)no->children[j]))); - //child = 0; + child = 0; } no->children[j] = child; @@ -1852,16 +1901,11 @@ static boolean P_LoadRawBlockMap(UINT8 *data, size_t count) // http://www.doomworld.com/idgames/index.php?id=12935 if (!P_VerifyBlockMap(count)) { -#ifdef PARANOIA - I_Error("P_LoadBlockMap: erroneous BLOCKMAP lump may cause crashes.\n"); -#endif - CONS_Alert(CONS_ERROR, "P_LoadBlockMap: erroneous BLOCKMAP lump may cause crashes.\n"); - - //Z_Free(blockmaplump); - //blockmaplump = NULL; - //return false; // ideally we would just let the game rebuild the blockmap - // but this has a chance of desynching vanilla clients - // not sure whats worse honestly and i do not want to decide that :chaosleep: + CorruptMapWarning(va("P_LoadBlockMap: corrupted or invalid BLOCKMAP lump! Check the log for more information.\n")); + // vanilla WILL crash here anyways so just rebuild it ourselves + Z_Free(blockmaplump); + blockmaplump = NULL; + return false; } // clear out mobj chains @@ -2004,11 +2048,16 @@ static void P_LoadReject(UINT8 *data, size_t rejectsize) { if (rejectsize < neededsize) { -#ifdef PARANOIA - I_Error("REJECT is %s byte%s too small. REJECT might be invalid and crash vanilla clients!\n", sizeu1(neededsize - rejectsize), (neededsize - rejectsize) == 1 ? "" : "s"); -#endif - CONS_Alert(CONS_ERROR, "REJECT is %s byte%s too small. REJECT might be invalid and crash vanilla clients!\n", sizeu1(neededsize - rejectsize), (neededsize - rejectsize) == 1 ? "" : "s"); + CorruptMapWarning(va("P_LoadReject: REJECT is %s byte%s too small. REJECT might be invalid!\n", sizeu1(neededsize - rejectsize), (neededsize - rejectsize) == 1 ? "" : "s")); +#ifdef COMPAT_VANILLA + // we can pad this and somewhat prevent desyncs + // probs not cool if the reject is from a completely different map + // but whatever allocsize = neededsize; +#else + rejectmatrix = NULL; + return; +#endif } rejectmatrix = Z_Calloc(allocsize, PU_LEVEL, NULL); // allocate memory for the reject matrix diff --git a/src/p_setup.h b/src/p_setup.h index c5ad15d44..1d986d925 100644 --- a/src/p_setup.h +++ b/src/p_setup.h @@ -114,6 +114,9 @@ size_t P_PrecacheLevelFlats(void); void P_AllocMapHeader(INT16 i); +void P_PrintCorruptMapWarnings(void); +void P_FreeCorruptMapWarnings(void); + #ifdef __cplusplus } // extern "C" #endif