From eba1cfb94de43ff1e602a31e63994100c67fc2b7 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 4 Nov 2026 00:18:52 +0100 Subject: [PATCH 1/6] remove "flatcheck" from HWR_PrecacheLevelFlats in practice this did nothing really would be more useful for encore but that aint working for us so whatever --- src/hardware/hw_cache.c | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 3b7704cee..d50076813 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -614,16 +614,8 @@ void HWR_FreeMapTextures(void) gl_numtextures = 0; } -#define NAME flatcheck -#define KEY_TY UINT32 -#define HASH_FN vt_hash_integer -#define CMPR_FN vt_cmpr_integer -#include "../verstable.h" - static void HWR_PrecacheLevelFlats(void) { - // lookup for flats that may´ve been already loaded - flatcheck flatpresent; size_t i; INT32 k; @@ -635,9 +627,6 @@ static void HWR_PrecacheLevelFlats(void) } #endif - flatcheck_init(&flatpresent); - flatcheck_reserve(&flatpresent, numlevelflats); - // special case for encore #if 0 #ifdef GLENCORE @@ -689,11 +678,7 @@ static void HWR_PrecacheLevelFlats(void) { const levelflat_t *levelflat = &levelflats[i]; - if (flatcheck_is_end(flatcheck_get(&flatpresent, levelflat->lumpnum))) - { - HWR_GetFlat(levelflat->lumpnum, false); - flatcheck_insert(&flatpresent, levelflat->lumpnum); - } + HWR_GetFlat(levelflat->lumpnum, false); if (levelflat->speed) // is it an animated flat ? { @@ -701,17 +686,11 @@ static void HWR_PrecacheLevelFlats(void) for (k = 0; k < levelflat->numpics; k++) { lumpnum_t lump = levelflat->baselumpnum + k; - if (flatcheck_is_end(flatcheck_get(&flatpresent, lump))) - { - HWR_GetFlat(lump, false); - flatcheck_insert(&flatpresent, lump); - } + HWR_GetFlat(lump, false); } } } } - - flatcheck_cleanup(&flatpresent); } static void HWR_PrecacheLevelTextures(void) From cb5d3ab4e1bfc883d833894f21852b0012e9fd64 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 4 Nov 2026 01:38:15 +0100 Subject: [PATCH 2/6] add compile flag for building with thread sanitizer indev noticed thats a thing that exists wouldve been quite useful a bunch of times before lol also some fixes for the other sanitizer flags --- src/CMakeLists.txt | 2 ++ src/Makefile | 23 ++++++++++++++++++----- src/dedicated/CMakeLists.txt | 11 ++++++++--- src/sdl/CMakeLists.txt | 11 ++++++++--- 4 files changed, 36 insertions(+), 11 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2618d4077..d4296d362 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -246,6 +246,8 @@ set(SRB2_CONFIG_ASAN OFF CACHE BOOL "Compile with AddressSanitizer (libasan).") set(SRB2_CONFIG_UBSAN OFF CACHE BOOL "Compile with UndefinedBehaviorSanitizer (libubsan).") +set(SRB2_CONFIG_TSAN OFF CACHE BOOL + "Compile with ThreadSanitizer (libtsan).") set(SRB2_CONFIG_MUMBLE ON CACHE BOOL "Enable Mumble support") diff --git a/src/Makefile b/src/Makefile index 27831946a..159d3f7d0 100644 --- a/src/Makefile +++ b/src/Makefile @@ -75,6 +75,7 @@ # PROFILEMODE=1 - Enable performance profiling (gprof). # USEASAN=1 - Enable building with Address Sanitizer. # USEUBSAN=1 - Enable building with Undefined Behavior Sanitizer. +# USETSAN=1 - Enable building with Thread Sanitizer. # NOLIBBACKTRACE=1 - Disable using Libbacktrace for crashlog traces. # # General flags for building: @@ -261,23 +262,35 @@ debug_opts=-D_DEBUG else # build a normal optimized version debug_opts=-DNDEBUG opts+=-O3 -ifndef NOLTO -# compile with LTO -opts+=-flto=auto -libs+=-flto=auto -endif endif ifdef USEASAN # compile with asan opts+=-O1 -fsanitize=address -fno-omit-frame-pointer -fno-common libs+=-fsanitize=address +NOLTO=1 endif ifdef USEUBSAN # compile with ubsan opts+=-O1 -fsanitize=undefined -fno-omit-frame-pointer libs+=-fsanitize=undefined +NOLTO=1 +endif + +ifdef USETSAN +# compile with tsan +opts+=-O1 -fsanitize=thread -fno-omit-frame-pointer +libs+=-fsanitize=thread +NOLTO=1 +endif + +ifndef DEBUGMODE +ifndef NOLTO +# compile with LTO +opts+=-flto=auto +libs+=-flto=auto +endif endif ifdef USEJEMALLOC diff --git a/src/dedicated/CMakeLists.txt b/src/dedicated/CMakeLists.txt index 38fb179f0..923f55596 100644 --- a/src/dedicated/CMakeLists.txt +++ b/src/dedicated/CMakeLists.txt @@ -119,20 +119,25 @@ target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_THREADS ) -if(SRB2_CONFIG_LTO AND NOT SRB2_CONFIG_DEBUGMODE) +if(SRB2_CONFIG_LTO AND NOT SRB2_CONFIG_DEBUGMODE AND NOT SRB2_CONFIG_ASAN AND NOT SRB2_CONFIG_UBSAN AND NOT SRB2_CONFIG_TSAN) set_property(TARGET SRB2SDL2 PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) endif() if(SRB2_CONFIG_ASAN) - target_compile_options(SRB2SDL2 PRIVATE -fsanitize=address) + target_compile_options(SRB2SDL2 PRIVATE -O1 -fsanitize=address -fno-omit-frame-pointer -fno-common) target_link_options(SRB2SDL2 PRIVATE -fsanitize=address) endif() if(SRB2_CONFIG_UBSAN) - target_compile_options(SRB2SDL2 PRIVATE -fsanitize=undefined) + target_compile_options(SRB2SDL2 PRIVATE -O1 -fsanitize=undefined -fno-omit-frame-pointer) target_link_options(SRB2SDL2 PRIVATE -fsanitize=undefined) endif() +if(SRB2_CONFIG_TSAN) + target_compile_options(SRB2SDL2 PRIVATE -O1 -fsanitize=thread -fno-omit-frame-pointer) + target_link_options(SRB2SDL2 PRIVATE -fsanitize=thread) +endif() + ## strip debug symbols into separate file when using gcc # if(CMAKE_COMPILER_IS_GNUCC) # if(${CMAKE_BUILD_TYPE} MATCHES Debug) diff --git a/src/sdl/CMakeLists.txt b/src/sdl/CMakeLists.txt index 664010072..866d2bc55 100644 --- a/src/sdl/CMakeLists.txt +++ b/src/sdl/CMakeLists.txt @@ -233,20 +233,25 @@ if(${SDL2_FOUND}) -DHAVE_THREADS ) - if(SRB2_CONFIG_LTO AND NOT SRB2_CONFIG_DEBUGMODE) + if(SRB2_CONFIG_LTO AND NOT SRB2_CONFIG_DEBUGMODE AND NOT SRB2_CONFIG_ASAN AND NOT SRB2_CONFIG_UBSAN AND NOT SRB2_CONFIG_TSAN) set_property(TARGET SRB2SDL2 PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) endif() if(SRB2_CONFIG_ASAN) - target_compile_options(SRB2SDL2 PRIVATE -fsanitize=address) + target_compile_options(SRB2SDL2 PRIVATE -O1 -fsanitize=address -fno-omit-frame-pointer -fno-common) target_link_options(SRB2SDL2 PRIVATE -fsanitize=address) endif() if(SRB2_CONFIG_UBSAN) - target_compile_options(SRB2SDL2 PRIVATE -fsanitize=undefined) + target_compile_options(SRB2SDL2 PRIVATE -O1 -fsanitize=undefined -fno-omit-frame-pointer) target_link_options(SRB2SDL2 PRIVATE -fsanitize=undefined) endif() + if(SRB2_CONFIG_TSAN) + target_compile_options(SRB2SDL2 PRIVATE -O1 -fsanitize=thread -fno-omit-frame-pointer) + target_link_options(SRB2SDL2 PRIVATE -fsanitize=thread) + endif() + if(NOT SRB2_CONFIG_MUMBLE) target_compile_options(SRB2SDL2 PRIVATE -DNOMUMBLE) endif() From d43b60ad8346a0593ce98ecafeee84eba70ba050 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 5 Nov 2026 15:37:38 +0100 Subject: [PATCH 3/6] fix blendmodes and line translucency on polyobject sides in gl this is also how vanilla kart handled this code eitherways --- src/hardware/hw_main.cpp | 70 +++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 36 deletions(-) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index f862cf18e..d00b42918 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -1239,46 +1239,44 @@ static inline boolean HWR_BlendMidtextureSurface(FSurfaceInfo *pSurf) pSurf->PolyColor.s.alpha = 0xFF; - if (LIKELY(!gl_curline->polyseg)) - { - // check if linedef alpha is within range - const boolean linealpha = (gl_linedef->alpha >= 0 && gl_linedef->alpha < FRACUNIT); + // check if linedef alpha is within range + const boolean linealpha = (gl_linedef->alpha >= 0 && gl_linedef->alpha < FRACUNIT); - // set alpha for transparent walls - switch (gl_linedef->special) - { - // Translucent linedef types - case 102: - case 121 ... 125: - case 141 ... 145: - case 174: - case 175: - case 192: - case 195: - case 221: - case 253: - case 256: - if (gl_linedef->blendmode && linealpha) + // set alpha for transparent walls + switch (gl_linedef->special) + { + // Translucent linedef types + case 102: + case 121 ... 125: + case 141 ... 145: + case 174: + case 175: + case 192: + case 195: + case 221: + case 253: + case 256: + if (gl_linedef->blendmode && linealpha) + blendmode = HWR_SurfaceBlend(gl_linedef->blendmode, R_GetLinedefTransTable(gl_linedef->alpha), pSurf); + else + blendmode = PF_Translucent; + break; + default: + if (gl_linedef->blendmode) + { + if (linealpha) blendmode = HWR_SurfaceBlend(gl_linedef->blendmode, R_GetLinedefTransTable(gl_linedef->alpha), pSurf); else - blendmode = PF_Translucent; - break; - default: - if (gl_linedef->blendmode) - { - if (linealpha) - blendmode = HWR_SurfaceBlend(gl_linedef->blendmode, R_GetLinedefTransTable(gl_linedef->alpha), pSurf); - else - blendmode = HWR_GetBlendModeFlag(gl_linedef->blendmode); - } - else if (linealpha) - blendmode = HWR_TranstableToAlpha(R_GetLinedefTransTable(gl_linedef->alpha), pSurf); - else - blendmode = PF_Masked; - break; - } + blendmode = HWR_GetBlendModeFlag(gl_linedef->blendmode); + } + else if (linealpha) + blendmode = HWR_TranstableToAlpha(R_GetLinedefTransTable(gl_linedef->alpha), pSurf); + else + blendmode = PF_Masked; + break; } - else if (gl_curline->polyseg->translucency > 0) + + if (gl_curline->polyseg && gl_curline->polyseg->translucency > 0) { // Polyobject translucency is shared between all of its lines if (gl_curline->polyseg->translucency >= NUMTRANSMAPS) // wall not drawn From b8aaf63b201fce485b53a130a96db4d339e77efb Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 5 Nov 2026 15:32:22 +0100 Subject: [PATCH 4/6] use "rawlinedef" when checking for seg issues smth smth byte order or whatever but is consistent with the rest of the code anyways --- src/p_setup.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index 14a911743..ea4295df4 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -570,13 +570,13 @@ static void P_LoadSegs(UINT8 *data) if (seg->sidedef == &sides[seg->linedef->sidenum[0]]) { - seg->v1 = lines[ms->linedef].v1; - seg->v2 = lines[ms->linedef].v2; + seg->v1 = lines[rawlinedef].v1; + seg->v2 = lines[rawlinedef].v2; } else { - seg->v1 = lines[ms->linedef].v2; - seg->v2 = lines[ms->linedef].v1; + seg->v1 = lines[rawlinedef].v2; + seg->v2 = lines[rawlinedef].v1; } } else @@ -584,7 +584,6 @@ static void P_LoadSegs(UINT8 *data) seg->v1 = &vertexes[v1]; seg->v2 = &vertexes[v2]; } - #ifdef HWRENDER if (rendermode == render_opengl) { @@ -597,7 +596,6 @@ static void P_LoadSegs(UINT8 *data) //seg->fv2.z = FixedToFloat(seg->v2->z); } #endif - seg->length = P_SegLength(seg); P_UpdateSegLightOffset(seg); From c1a0b97c54c8498f87588597667f1d0be3165072 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 5 Nov 2026 15:33:40 +0100 Subject: [PATCH 5/6] add checks for missing bsp lumps not sure why there werent any, the other map lumps have those, and a corrupted file may have those missing also which would just crash instead of telling you wtf is wrong --- src/p_setup.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/p_setup.c b/src/p_setup.c index ea4295df4..ee2130279 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -2094,6 +2094,13 @@ static void P_LoadMapBSP(const virtres_t* virt) virtlump_t* virtsegs = vres_Find(virt, "SEGS"); virtlump_t* virtnodes = vres_Find(virt, "NODES"); + if (!virtssectors) + I_Error("SSECTORS lump not found"); + if (!virtsegs) + I_Error("SEGS lump not found"); + if (!virtnodes) + I_Error("NODES lump not found"); + numsubsectors = virtssectors->size / sizeof(mapsubsector_t); numnodes = virtnodes->size / sizeof(mapnode_t); numsegs = virtsegs->size / sizeof(mapseg_t); From e54b6a780d56b0308527aed84fc136999d4a3076 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 5 Nov 2026 15:31:25 +0100 Subject: [PATCH 6/6] "fix" skywalls on hadal trench and candy lake this whole sky handling is just incredibly stupid and wouldve been such an easy fix, but here we go this is just more stupid hacks but i really dont feel bad here since the code already hacked around a bunch of shit just hoping this wont cause any issues on some maps and needs testing sigh --- src/hardware/hw_main.cpp | 44 ++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index d00b42918..80549f240 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -1383,7 +1383,8 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom // two sided line if (gl_backsector) { - INT32 gl_toptexture = 0, gl_bottomtexture = 0; + const INT32 gl_toptexture = R_GetTextureNum(gl_sidedef->toptexture); + const INT32 gl_bottomtexture = R_GetTextureNum(gl_sidedef->bottomtexture); fixed_t texturevpeg; @@ -1394,7 +1395,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if (!gl_curline->polyseg) // Don't do it for polyobjects { // Sky Ceilings - wallVerts[3].y = wallVerts[2].y = FLOATMAX; + wallVerts[2].y = wallVerts[3].y = FLOATMAX; // draw to top of map space auto draw_sky_walls = [] (int vert1, int vert2, fixed_t world, fixed_t worldslope, auto& wwallVerts, auto& sSurf) FUNCINLINE @@ -1404,6 +1405,9 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom HWR_DrawSkyWall(wwallVerts, &sSurf); }; + // worldtop = front ceiling + // worldhigh = back ceiling + if (gl_frontsector->ceilingpic == skyflatnum) { if (gl_backsector->ceilingpic == skyflatnum) @@ -1422,6 +1426,17 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom worldtop = worldhigh; worldtopslope = worldhighslope; } + else if (!gl_toptexture && + (worldhigh <= worldtop && worldhighslope <= worldtopslope) && // Assuming ESLOPE is always on with my changes + (worldhigh != worldtop || worldhighslope != worldtopslope)) + { + // Only the frontsector is sky. + // If there's no upper texture, extend the sky wall + // down to the lower of the two ceilings. + fixed_t top = std::min(worldtop, worldhigh); + fixed_t topslope = std::min(worldtopslope, worldhighslope); + draw_sky_walls(0, 1, top, topslope, wallVerts, Surf); + } else { // Only the frontsector is sky, just draw a skywall from the front ceiling @@ -1434,8 +1449,11 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom draw_sky_walls(0, 1, worldtop, worldtopslope, wallVerts, Surf); } + // worldbottom = front floor + // worldlow = back floor + // Sky Floors - wallVerts[0].y = wallVerts[1].y = FLOATMIN; + wallVerts[0].y = wallVerts[1].y = FLOATMIN; // draw to bottom of map space if (gl_frontsector->floorpic == skyflatnum) { @@ -1447,7 +1465,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if ((worldlow >= worldbottom && worldlowslope >= worldbottomslope) && (worldlow != worldbottom || worldlowslope != worldbottomslope) // Removing the second line above will render more rarely visible skywalls. Example: Cave garden ceiling in Dark race - && !(gl_sidedef->bottomtexture)) + && !(gl_bottomtexture)) { draw_sky_walls(3, 2, worldlow, worldlowslope, wallVerts, Surf); } @@ -1458,15 +1476,25 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom draw_sky_walls(3, 2, worldbottom, worldbottomslope, wallVerts, Surf); } } - else if ((gl_backsector->floorpic == skyflatnum) && !(gl_sidedef->bottomtexture)) + else if ((gl_backsector->floorpic == skyflatnum) && !(gl_bottomtexture)) { // Only the backsector has sky, just draw a skywall from the back floor if there's no bottomtexture draw_sky_walls(3, 2, worldlow, worldlowslope, wallVerts, Surf); } + else if (gl_frontsector->ceilingpic == skyflatnum && + gl_backsector->ceilingpic == skyflatnum && + (worldlow >= worldbottom && worldlowslope >= worldbottomslope) + && (worldlow != worldbottom || worldlowslope != worldbottomslope) + // Removing the second line above will render more rarely visible skywalls. Example: Cave garden ceiling in Dark race + && !(gl_bottomtexture)) + { + // Both ceilings are sky, but neither floor is sky. + // If there's a lower wall gap without a bottom texture, + // draw a skywall from the backsector's higher floor. + draw_sky_walls(3, 2, worldlow, worldlowslope, wallVerts, Surf); + } } - gl_toptexture = R_GetTextureNum(gl_sidedef->toptexture); - // check TOP TEXTURE if (gl_toptexture && (worldhighslope < worldtopslope || worldhigh < worldtop)) { @@ -1530,8 +1558,6 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom HWR_ProjectWall(wallVerts, &Surf, PF_Masked, lightnum, colormap); } - gl_bottomtexture = R_GetTextureNum(gl_sidedef->bottomtexture); - // check BOTTOM TEXTURE if (gl_bottomtexture && (worldlowslope > worldbottomslope || worldlow > worldbottom)) {