From b99cd88947ea419b3a6b347114b16f31ba373da1 Mon Sep 17 00:00:00 2001 From: Indev Date: Tue, 21 Oct 2025 01:46:29 +0300 Subject: [PATCH 01/14] Fix possible buffer overflow in M_TextInputSetString when string length is greatter than buffer length --- src/m_textinput.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/m_textinput.c b/src/m_textinput.c index 882d35e35..049222701 100644 --- a/src/m_textinput.c +++ b/src/m_textinput.c @@ -239,8 +239,8 @@ void M_TextInputClear(textinput_t *input) void M_TextInputSetString(textinput_t *input, const char *c) { memset(input->buffer, 0, input->buffer_size); - strcpy(input->buffer, c); - input->cursor = input->select = input->length = strlen(c); + strncpy(input->buffer, c, input->buffer_size); + input->cursor = input->select = input->length = strlen(input->buffer); } static boolean M_TextInputHandleBase(textinput_t *input, INT32 key, boolean emotes) From 4c04d09d1895259d0d744cdd2f9226fd67b06c2c Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 21 Oct 2025 00:49:05 +0200 Subject: [PATCH 02/14] rename --- src/r_plane.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/r_plane.cpp b/src/r_plane.cpp index f4eb61410..bab6fcb6b 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -739,7 +739,7 @@ void R_DrawPlanes(void) #endif } -static void R_DrawSkyPlane(visplane_t *pl, void(*colfunc2)(drawcolumndata_t*), boolean allow_parallel); +static void R_DrawSkyPlane(visplane_t *pl, void(*skycolfunc)(drawcolumndata_t*), boolean allow_parallel); void R_DrawSkyPlanes(void) { @@ -774,7 +774,7 @@ void R_DrawSkyPlanes(void) #endif } -static void R_DrawSkyPlane(visplane_t *pl, void(*colfunc2)(drawcolumndata_t*), boolean allow_parallel) +static void R_DrawSkyPlane(visplane_t *pl, void(*skycolfunc)(drawcolumndata_t*), boolean allow_parallel) { INT32 x; @@ -834,7 +834,7 @@ static void R_DrawSkyPlane(visplane_t *pl, void(*colfunc2)(drawcolumndata_t*), b dc.x = x + i; dc.source = R_GetColumn(texture, -angle); // get negative of angle for each column to display sky correct way round! --Monster Iestyn 27/01/18 - colfunc2(&dc); + skycolfunc(&dc); } }; @@ -868,10 +868,9 @@ static void R_DrawSkyPlane(visplane_t *pl, void(*colfunc2)(drawcolumndata_t*), b dc.iscale = FixedMul(skyscale, FINECOSINE(xtoviewangle[x]>>ANGLETOFINESHIFT)); dc.x = x; dc.source = - R_GetColumn(texturetranslation[skytexture], - -angle); // get negative of angle for each column to display sky correct way round! --Monster Iestyn 27/01/18 + R_GetColumn(texturetranslation[skytexture], -angle); // get negative of angle for each column to display sky correct way round! --Monster Iestyn 27/01/18 - colfunc2(&dc); + skycolfunc(&dc); } #endif } From 1acae3e4af2da4f36063847abda286953dbe14d2 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 21 Oct 2025 00:55:18 +0200 Subject: [PATCH 03/14] use malloc for spawnstate mapdata copies they might be somewhat large and get completely overwritten eitherway so save us the 0 init --- src/p_setup.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index 5cf9fef39..73445b6b3 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1986,9 +1986,9 @@ static void P_LoadMapData(const virtres_t* virt) P_InitTagLists(); // Create xref tables for tags // Copy relevant map data for NetArchive purposes. - spawnsectors = Z_Calloc(numsectors * sizeof(*sectors), PU_LEVEL, NULL); - spawnlines = Z_Calloc(numlines * sizeof(*lines), PU_LEVEL, NULL); - spawnsides = Z_Calloc(numsides * sizeof(*sides), PU_LEVEL, NULL); + spawnsectors = Z_Malloc(numsectors * sizeof(*sectors), PU_LEVEL, NULL); + spawnlines = Z_Malloc(numlines * sizeof(*lines), PU_LEVEL, NULL); + spawnsides = Z_Malloc(numsides * sizeof(*sides), PU_LEVEL, NULL); memcpy(spawnsectors, sectors, numsectors * sizeof(*sectors)); memcpy(spawnlines, lines, numlines * sizeof(*lines)); From 71e9c4f5af0a5feeebf8853be67b7e5945cf960b Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 21 Oct 2025 01:25:00 +0200 Subject: [PATCH 04/14] use "viewssnum" for shadowdir stuff --- src/hardware/hw_main.cpp | 46 +++++++++++++++++----------------------- src/r_main.cpp | 2 +- 2 files changed, 21 insertions(+), 27 deletions(-) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index af797af11..45f25c2a6 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -3376,6 +3376,9 @@ static void HWR_DrawSpriteShadow(gl_vissprite_t *spr, patch_t *gpatch, GLPatch_t fixed_t slopez; float offset = 0; + if (!spr->mobj) + return; + R_GetShadowZ(spr->mobj, &floorslope); mobjfloor = HWR_OpaqueFloorAtPos( @@ -3387,14 +3390,7 @@ static void HWR_DrawSpriteShadow(gl_vissprite_t *spr, patch_t *gpatch, GLPatch_t angle_t shadowdir; // Set direction - if (splitscreen && R_GetViewNumber() == 1) - shadowdir = localangle[1] + FixedAngle(cv_cam_rotate[1].value); - else if (splitscreen > 1 && R_GetViewNumber() == 2) - shadowdir = localangle[2] + FixedAngle(cv_cam_rotate[2].value); - else if (splitscreen > 2 && R_GetViewNumber() == 3) - shadowdir = localangle[3] + FixedAngle(cv_cam_rotate[3].value); - else - shadowdir = localangle[0] + FixedAngle(cv_cam_rotate[0].value); + shadowdir = localangle[viewssnum] + FixedAngle(cv_cam_rotate[viewssnum].value); // Find floorheight floorheight = HWR_OpaqueFloorAtPos( @@ -3406,18 +3402,17 @@ static void HWR_DrawSpriteShadow(gl_vissprite_t *spr, patch_t *gpatch, GLPatch_t // Don't draw it, then! if (spr->mobj->z < floorheight) return; - else - { - fixed_t floorz; - floorz = HWR_OpaqueFloorAtPos( - spr->mobj->x + P_ReturnThrustX(spr->mobj, shadowdir, spr->mobj->z - floorheight), - spr->mobj->y + P_ReturnThrustY(spr->mobj, shadowdir, spr->mobj->z - floorheight), - spr->mobj->z, spr->mobj->height); - // The shadow would be falling on a wall? Don't draw it, then. - // Would draw midair otherwise. - if (floorz < floorheight) - return; - } + + fixed_t floorz; + floorz = HWR_OpaqueFloorAtPos( + spr->mobj->x + P_ReturnThrustX(spr->mobj, shadowdir, spr->mobj->z - floorheight), + spr->mobj->y + P_ReturnThrustY(spr->mobj, shadowdir, spr->mobj->z - floorheight), + spr->mobj->z, spr->mobj->height); + + // The shadow would be falling on a wall? Don't draw it, then. + // Would draw midair otherwise. + if (floorz < floorheight) + return; floorheight = FixedInt(spr->mobj->z - floorheight); @@ -3427,12 +3422,11 @@ static void HWR_DrawSpriteShadow(gl_vissprite_t *spr, patch_t *gpatch, GLPatch_t floorheight = FixedInt(spr->mobj->z - mobjfloor); // technically this_scale gets multiplied and added to sprite y/x scale, but this thing needs it for some crap so ill just throw it in here again - const boolean hires = (spr->mobj && spr->mobj->skin && K_GetMobjSkin(spr->mobj)->flags & SF_HIRES); + this_scale = FixedToFloat(spr->mobj->scale); - if (spr->mobj) - this_scale = FixedToFloat(spr->mobj->scale); - if (hires) - this_scale = this_scale * FixedToFloat(K_GetMobjSkin(spr->mobj)->highresscale); + const skin_t *moskin = K_GetMobjSkin(spr->mobj); + if (moskin && moskin->flags & SF_HIRES) + this_scale *= FixedToFloat(moskin->highresscale); // create the sprite billboard // @@ -4053,7 +4047,7 @@ static void HWR_DrawPrecipitationSprite(gl_vissprite_t *spr) const precipmobj_t *sprmo = spr->precip; - if (UNLIKELY(!sprmo || !sprmo->subsector)) + if (UNLIKELY(!sprmo->subsector)) return; // cache sprite graphics diff --git a/src/r_main.cpp b/src/r_main.cpp index 50185d016..4686036a7 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -63,7 +63,7 @@ size_t loopcount; fixed_t viewx, viewy, viewz; angle_t viewangle, aimingangle, viewroll; -UINT8 viewssnum; +UINT8 viewssnum = 0; fixed_t viewcos, viewsin; boolean skyVisible; boolean skyVisiblePerPlayer[MAXSPLITSCREENPLAYERS]; // saved values of skyVisible for each splitscreen player From 51b8dc9101c60fcce8531c3b03954d937a930a2e Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 21 Oct 2025 14:44:43 +0200 Subject: [PATCH 05/14] m_menu: add textinput special case for playername string itself it already checks to not write out of bounds, this is mostly just to fix visual issues kind hacky, but works for now --- src/m_menu.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/m_menu.c b/src/m_menu.c index 3d8857b9a..86045dfcd 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -702,7 +702,13 @@ static void M_CheckStringItem(void) // Just in case memset(menu_text_input_buf, 0, sizeof menu_text_input_buf); - M_TextInputInit(&menuinput, menu_text_input_buf, sizeof menu_text_input_buf); + + // special case: name input, cap it to prevent writing outside the textbox + // kinda ugly but itll work + if (cv == &cv_playername) + M_TextInputInit(&menuinput, menu_text_input_buf, MAXPLAYERNAME +1); + else + M_TextInputInit(&menuinput, menu_text_input_buf, sizeof menu_text_input_buf); M_TextInputSetString(&menuinput, cv->string); } From f2314174652d9345dd5cfb48467b7b9edb9dcbd7 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 21 Oct 2025 15:25:33 +0200 Subject: [PATCH 06/14] fix splitscreen view in gl --- src/d_main.c | 60 +++++++++++++++++++++++----------------------------- 1 file changed, 26 insertions(+), 34 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 33dc57689..5bbfee406 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -363,16 +363,36 @@ static void D_Renderview(void) for (i = 0; i <= splitscreen; i++) { - const boolean issplitscreen = (i > 0); - if (!P_MobjWasRemoved(players[displayplayers[i]].mo) || players[displayplayers[i]].playerstate == PST_DEAD) { viewssnum = i; - if (!issplitscreen) // Initialize for P1 + switch (i) { - viewwindowy = viewwindowx = 0; - objectsdrawn = 0; + case 1: + if (splitscreen > 1) + { + viewwindowx = viewwidth; + viewwindowy = 0; + } + else + { + viewwindowx = 0; + viewwindowy = viewheight; + } + break; + case 2: + viewwindowx = 0; + viewwindowy = viewheight; + break; + case 3: + viewwindowx = viewwidth; + viewwindowy = viewheight; + break; + default: // Initialize for P1 + viewwindowy = viewwindowx = 0; + objectsdrawn = 0; + break; } #ifdef HWRENDER @@ -383,38 +403,10 @@ static void D_Renderview(void) continue; } #endif - if (issplitscreen) // Splitscreen-specific - { - switch (i) - { - case 1: - if (splitscreen > 1) - { - viewwindowx = viewwidth; - viewwindowy = 0; - } - else - { - viewwindowx = 0; - viewwindowy = viewheight; - } - break; - case 2: - viewwindowx = 0; - viewwindowy = viewheight; - break; - case 3: - viewwindowx = viewwidth; - viewwindowy = viewheight; - default: - break; - } - } - R_RenderPlayerView(&players[displayplayers[i]]); } - if (!issplitscreen) + if (i == 0) R_ApplyViewMorph(); V_DoPostProcessor(i, postimgparam[i]); From 0dad927c0530e43a81e497e344c9329084eb5066 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 21 Oct 2025 15:42:23 +0200 Subject: [PATCH 07/14] fix 4th player background not drawin in gl in 3 player splitscreen --- src/d_main.c | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 5bbfee406..1bc346deb 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -347,20 +347,6 @@ static void D_Renderview(void) } } - // Draw over the fourth screen so you don't have to stare at a HOM :V - if (splitscreen == 2) - { - // V_DrawPatchFill, but for the fourth screen only - patch_t *pat = W_CachePatchName("SRB2BACK", PU_CACHE); - INT32 x, y, pw = SHORT(pat->width) * vid.dup, ph = SHORT(pat->height) * vid.dup; - - for (x = vid.width>>1; x < vid.width; x += pw) - { - for (y = vid.height>>1; y < vid.height; y += ph) - V_DrawScaledPatch(x, y, V_NOSCALESTART, pat); - } - } - for (i = 0; i <= splitscreen; i++) { if (!P_MobjWasRemoved(players[displayplayers[i]].mo) || players[displayplayers[i]].playerstate == PST_DEAD) @@ -399,17 +385,34 @@ static void D_Renderview(void) if (rendermode == render_opengl) { HWR_RenderPlayerView(); - R_RestoreLevelInterpolators(); - continue; } + else if (rendermode == render_soft) #endif + R_RenderPlayerView(&players[displayplayers[i]]); } - if (i == 0) - R_ApplyViewMorph(); + if (rendermode == render_soft) + { + if (i == 0) + R_ApplyViewMorph(); - V_DoPostProcessor(i, postimgparam[i]); + V_DoPostProcessor(i, postimgparam[i]); + } + } + + // Draw over the fourth screen so you don't have to stare at a HOM :V + if (splitscreen == 2) + { + // V_DrawPatchFill, but for the fourth screen only + patch_t *pat = W_CachePatchName("SRB2BACK", PU_PATCH); + INT32 x, y, pw = SHORT(pat->width) * vid.dup, ph = SHORT(pat->height) * vid.dup; + + for (x = vid.width>>1; x < vid.width; x += pw) + { + for (y = vid.height>>1; y < vid.height; y += ph) + V_DrawScaledPatch(x, y, V_NOSCALESTART, pat); + } } R_RestoreLevelInterpolators(); From 4c5d34e82c0a275fd76dfcc8ae61e4899d336344 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 21 Oct 2025 16:09:02 +0200 Subject: [PATCH 08/14] Revert "Fix ghost hitlist causing zone errors (closes #118)" This reverts commit ab13b2810669a77e6e1c5f06189a93c71b8448ec. --- src/g_demo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/g_demo.c b/src/g_demo.c index 4b63a1578..6b2c8f1c9 100644 --- a/src/g_demo.c +++ b/src/g_demo.c @@ -630,7 +630,7 @@ void G_GhostAddHit(INT32 playernum, mobj_t *victim) ghostext[playernum].flags |= EZT_HIT; ghostext[playernum].hits++; - Z_Realloc(ghostext[playernum].hitlist, ghostext[playernum].hits * sizeof(mobj_t *), PU_STATIC, &ghostext[playernum].hitlist); + ghostext[playernum].hitlist = Z_Realloc(ghostext[playernum].hitlist, ghostext[playernum].hits * sizeof(mobj_t *), PU_LEVEL, &ghostext[playernum].hitlist); P_SetTarget(ghostext[playernum].hitlist + (ghostext[playernum].hits-1), victim); } From f5e7b65ae0f76141e7b4c41a0453b7b177b84b8d Mon Sep 17 00:00:00 2001 From: Indev Date: Tue, 21 Oct 2025 17:11:25 +0300 Subject: [PATCH 09/14] Fix replay names not displaying if you have more than INT16_MAX replays --- src/m_menu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 86045dfcd..6822dd499 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -4339,7 +4339,7 @@ static void DrawReplayHutReplayInfo(void) static void M_DrawReplayHut(void) { INT32 x, y, cursory = 0; - INT16 i; + INT32 i; INT16 replaylistitem = currentMenu->numitems-2; boolean processed_one_this_frame = false; const INT32 scaledviewheight = (vid.height/vid.dup); @@ -4412,7 +4412,7 @@ static void M_DrawReplayHut(void) V_DrawCenteredString(160, 100, V_ALLOWLOWERCASE, msg); } - for (i = 0; i < (INT16)replayqueryfound; i++) + for (i = 0; i < (INT32)replayqueryfound; i++) { INT32 localy = y+i*10; INT32 localx = x; From 1ac7852bd2b162283fdbd11042503b3c6172bcdb Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 21 Oct 2025 17:49:52 +0200 Subject: [PATCH 10/14] initialize a bunch of stuff that gets passed to realloc --- src/r_bsp.cpp | 2 +- src/r_data.c | 12 ++++++------ src/r_main.cpp | 2 +- src/r_plane.cpp | 18 +++++++++--------- src/r_things.cpp | 24 ++++++++++++------------ 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/r_bsp.cpp b/src/r_bsp.cpp index 6ef63739f..87d775c87 100644 --- a/src/r_bsp.cpp +++ b/src/r_bsp.cpp @@ -77,7 +77,7 @@ void R_ClearDrawSegs(void) // CPhipps - // Instead of clipsegs, let's try using an array with one entry for each column, // indicating whether it's blocked by a solid wall yet or not. -UINT8 *solidcol; +UINT8 *solidcol = NULL; void R_AllocClipSegMemory(void) { diff --git a/src/r_data.c b/src/r_data.c index 6c999d1ae..7afa1be73 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -94,17 +94,17 @@ static UINT32 **texturecolumnofs; // column offset lookup table for each texture UINT8 **texturecache; // graphics data for each generated full-size texture // texture width is a power of 2, so it can easily repeat along sidedefs using a simple mask -static INT32 *texturewidth; +static INT32 *texturewidth = NULL; -fixed_t *textureheight; // needed for texture pegging +fixed_t *textureheight = NULL; // needed for texture pegging -INT32 *texturetranslation; +INT32 *texturetranslation = NULL; // needed for pre rendering -sprcache_t *spritecachedinfo; +sprcache_t *spritecachedinfo = NULL; -lighttable_t *colormaps; -UINT8 *encoremap; +lighttable_t *colormaps = NULL; +UINT8 *encoremap = NULL; #ifdef HASINVERT UINT8 invertmap[256]; #endif diff --git a/src/r_main.cpp b/src/r_main.cpp index 4686036a7..33569fe80 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -88,7 +88,7 @@ INT32 viewangletox[FINEANGLES/2]; // The xtoviewangleangle[] table maps a screen pixel // to the lowest viewangle that maps back to x ranges // from clipangle to -clipangle. -angle_t *xtoviewangle; +angle_t *xtoviewangle = NULL; lighttable_t *scalelight[LIGHTLEVELS][MAXLIGHTSCALE]; lighttable_t *scalelightfixed[MAXLIGHTSCALE]; diff --git a/src/r_plane.cpp b/src/r_plane.cpp index bab6fcb6b..1adccfba1 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -46,15 +46,15 @@ // good night sweet prince //#define SHITPLANESPARENCY -visplane_t *visplanes[MAXVISPLANES]; +visplane_t *visplanes[MAXVISPLANES] = {}; static visplane_t *freetail; static visplane_t **freehead = &freetail; visplane_t *floorplane; visplane_t *ceilingplane; -visffloor_t visffloor[MAXFFLOORS]; -INT32 numffloors; +visffloor_t visffloor[MAXFFLOORS] = {}; +INT32 numffloors = 0; //SoM: 3/23/2000: Boom visplane hashing routine. #define visplane_hash(picnum,lightlevel,height) \ @@ -65,8 +65,8 @@ INT32 numffloors; // floorclip starts out SCREENHEIGHT // ceilingclip starts out -1 // -INT16 *floorclip, *ceilingclip; -fixed_t *frontscale; +INT16 *floorclip = NULL, *ceilingclip = NULL; +fixed_t *frontscale = NULL; // // spanstart holds the start of a plane span @@ -81,13 +81,13 @@ static INT32 *spanstart; // (this is to calculate yslopes only when really needed) // (when mouselookin', yslope is moving into yslopetab) // Check R_SetupFrame, R_SetViewSize for more... -fixed_t *yslopetab; -fixed_t *yslope; +fixed_t *yslopetab = NULL; +fixed_t *yslope = NULL; fixed_t basexscale, baseyscale; -static INT16 *ffloor_f_clip; -static INT16 *ffloor_c_clip; +static INT16 *ffloor_f_clip = NULL; +static INT16 *ffloor_c_clip = NULL; static void R_SetTiltedSpan(drawspandata_t* ds, INT32 span); static void R_SetSlopePlaneVectors(drawspandata_t* ds, visplane_t *pl, INT32 y, fixed_t xoff, fixed_t yoff); diff --git a/src/r_things.cpp b/src/r_things.cpp index f27b7e6a2..796f6c4a2 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -60,8 +60,8 @@ typedef struct static lighttable_t **spritelights; // constant arrays used for psprite clipping and initializing clipping -INT16 *negonearray; -INT16 *screenheightarray; +INT16 *negonearray = NULL; +INT16 *screenheightarray = NULL; // // INITIALIZATION FUNCTIONS @@ -539,8 +539,8 @@ void R_ClearSprites(void) visspritecount = numvisiblesprites = clippedvissprites = 0; } -static INT16 *vissprite_clipbot[MAXVISSPRITES >> VISSPRITECHUNKBITS]; -static INT16 *vissprite_cliptop[MAXVISSPRITES >> VISSPRITECHUNKBITS]; +static INT16 *vissprite_clipbot[MAXVISSPRITES >> VISSPRITECHUNKBITS] = {0}; +static INT16 *vissprite_cliptop[MAXVISSPRITES >> VISSPRITECHUNKBITS] = {0}; static void R_AllocVisSpriteChunkMemory(UINT32 chunk) { @@ -574,16 +574,16 @@ static vissprite_t overflowsprite; static vissprite_t *R_GetVisSprite(UINT32 num) { - UINT32 chunk = num >> VISSPRITECHUNKBITS; + UINT32 chunk = num >> VISSPRITECHUNKBITS; - // Allocate chunk if necessary - if (!visspritechunks[chunk]) - { - Z_Malloc(sizeof(vissprite_t) * VISSPRITESPERCHUNK, PU_LEVEL, &visspritechunks[chunk]); - R_AllocVisSpriteChunkMemory(chunk); - } + // Allocate chunk if necessary + if (!visspritechunks[chunk]) + { + Z_Malloc(sizeof(vissprite_t) * VISSPRITESPERCHUNK, PU_LEVEL, &visspritechunks[chunk]); + R_AllocVisSpriteChunkMemory(chunk); + } - return visspritechunks[chunk] + (num & VISSPRITEINDEXMASK); + return visspritechunks[chunk] + (num & VISSPRITEINDEXMASK); } static vissprite_t *R_NewVisSprite(void) From 0f43f19b71f1ae24c9102c8271594fd5bbc147bd Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 21 Oct 2025 18:00:54 +0200 Subject: [PATCH 11/14] remove unused maskdraw_t struct --- src/r_data.c | 4 ++-- src/r_things.cpp | 11 ++--------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/r_data.c b/src/r_data.c index 7afa1be73..a796de138 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -90,8 +90,8 @@ INT32 numtextures = 0; // total number of textures found, // size of following tables texture_t **textures = NULL; -static UINT32 **texturecolumnofs; // column offset lookup table for each texture -UINT8 **texturecache; // graphics data for each generated full-size texture +static UINT32 **texturecolumnofs = NULL; // column offset lookup table for each texture +UINT8 **texturecache = NULL; // graphics data for each generated full-size texture // texture width is a power of 2, so it can easily repeat along sidedefs using a simple mask static INT32 *texturewidth = NULL; diff --git a/src/r_things.cpp b/src/r_things.cpp index 796f6c4a2..75c333cd4 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -43,13 +43,6 @@ #define MINZ (FRACUNIT*16) #define BASEYCENTER (BASEVIDHEIGHT/2) -typedef struct -{ - INT32 x1, x2; - INT32 column; - INT32 topclip, bottomclip; -} maskdraw_t; - // // Sprite rotation 0 is facing the viewer, // rotation 1 is one angle turn CLOCKWISE around the axis. @@ -600,8 +593,8 @@ static vissprite_t *R_NewVisSprite(void) // Masked means: partly transparent, i.e. stored // in posts/runs of opaque pixels. // -INT16 *mfloorclip; -INT16 *mceilingclip; +INT16 *mfloorclip = NULL; +INT16 *mceilingclip = NULL; fixed_t spryscale = 0, sprtopscreen = 0, sprbotscreen = 0; fixed_t windowtop = 0, windowbottom = 0; From 2009cdeaeb2c730c58e59050467598c8ee4ba80e Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 21 Oct 2025 18:24:14 +0200 Subject: [PATCH 12/14] init few more things --- src/r_plane.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/r_plane.cpp b/src/r_plane.cpp index 1adccfba1..543faec77 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -50,8 +50,8 @@ visplane_t *visplanes[MAXVISPLANES] = {}; static visplane_t *freetail; static visplane_t **freehead = &freetail; -visplane_t *floorplane; -visplane_t *ceilingplane; +visplane_t *floorplane = NULL; +visplane_t *ceilingplane = NULL; visffloor_t visffloor[MAXFFLOORS] = {}; INT32 numffloors = 0; @@ -84,7 +84,7 @@ static INT32 *spanstart; fixed_t *yslopetab = NULL; fixed_t *yslope = NULL; -fixed_t basexscale, baseyscale; +fixed_t basexscale = 0, baseyscale = 0; static INT16 *ffloor_f_clip = NULL; static INT16 *ffloor_c_clip = NULL; From f8e5049d7659de589ca7adbf33a72c22d1f991cc Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 21 Oct 2025 19:24:56 +0200 Subject: [PATCH 13/14] fix R_MakeSpans accessing "spanstart" out of bounds when in splitscreen it gets allocated for viewheight not vid.height! --- src/r_plane.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/r_plane.cpp b/src/r_plane.cpp index 543faec77..8ef47f722 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -616,14 +616,12 @@ void R_ExpandPlane(visplane_t *pl, INT32 start, INT32 stop) // static void R_MakeSpans(void (*mapfunc)(drawspandata_t* ds, void(*spanfunc)(drawspandata_t*), INT32, INT32, INT32, boolean), spandrawfunc_t* localspanfunc, drawspandata_t* ds, INT32 x, INT32 t1, INT32 b1, INT32 t2, INT32 b2, boolean allow_parallel) { - const INT32 vidheight = vid.height; - // Alam: from r_splats's R_RenderFloorSplat - if (t1 >= vidheight) t1 = vidheight-1; - if (b1 >= vidheight) b1 = vidheight-1; - if (t2 >= vidheight) t2 = vidheight-1; - if (b2 >= vidheight) b2 = vidheight-1; - if (x-1 >= vid.width) x = vid.width; + if (t1 >= viewheight) t1 = viewheight-1; + if (b1 >= viewheight) b1 = viewheight-1; + if (t2 >= viewheight) t2 = viewheight-1; + if (b2 >= viewheight) b2 = viewheight-1; + if (x-1 >= viewwidth) x = viewwidth; #ifdef HAVE_THREADS // We want to draw N spans per subtask to ensure the work is From 27433f6fb5ebbb27cca1528db908e78e63ebea71 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 21 Oct 2025 19:26:01 +0200 Subject: [PATCH 14/14] call R_SetupFreelook in R_ExecuteSetViewSize to instantly update our now stale yslope pointer! fixes random crashes when switching numbers of splitviews in replays --- src/r_fps.cpp | 2 +- src/r_fps.h | 1 + src/r_main.cpp | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/r_fps.cpp b/src/r_fps.cpp index ad8c97aed..98bfaf68b 100644 --- a/src/r_fps.cpp +++ b/src/r_fps.cpp @@ -172,7 +172,7 @@ static vector3_t *R_LerpVector3(const vector3_t *from, const vector3_t *to, fixe // recalc necessary stuff for mouseaiming // slopes are already calculated for the full possible view (which is 4*viewheight). // 18/08/18: (No it's actually 16*viewheight, thanks Lactozilla for finding this out) -static void R_SetupFreelook(void) +void R_SetupFreelook(void) { // clip it in the case we are looking a hardware 90 degrees full aiming // (lmps, network and use F12...) diff --git a/src/r_fps.h b/src/r_fps.h index 49ca669d3..7ad5e9f16 100644 --- a/src/r_fps.h +++ b/src/r_fps.h @@ -151,6 +151,7 @@ typedef struct levelinterpolator_s { }; } levelinterpolator_t; +void R_SetupFreelook(void); // Interpolates the current view variables (r_state.h) against the selected view context in R_SetViewContext void R_InterpolateView(fixed_t frac, boolean forceinvalid); // Special function just for software diff --git a/src/r_main.cpp b/src/r_main.cpp index 33569fe80..a340ef29c 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -960,6 +960,8 @@ void R_ExecuteSetViewSize(void) } } + R_SetupFreelook(); + am_recalc = true; }