From 4df9749570994e3fd6e8d1f77c3b3c4bc1381b59 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Tue, 15 Aug 2023 03:28:37 +0200 Subject: [PATCH 1/9] Fix FreeMipmapColormap Crash Backport from SRB2 See: https://git.do.srb2.org/STJr/SRB2/-/commit/e9e0683d5efa1c21b0da5d698acd124421c90c42 Credits go to Lactozilla --- src/hardware/hw_cache.c | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index eed592af..35472b85 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -479,14 +479,39 @@ void HWR_InitTextureCache(void) // Callback function for HWR_FreeTextureCache. static void FreeMipmapColormap(INT32 patchnum, void *patch) { - GLPatch_t* const grpatch = patch; + GLPatch_t* const pat = patch; (void)patchnum; //unused - while (grpatch->mipmap->nextcolormap) + + // The patch must be valid, obviously + if (!pat) + return; + + // The mipmap must be valid, obviously + while (pat->mipmap) { - GLMipmap_t *grmip = grpatch->mipmap->nextcolormap; - grpatch->mipmap->nextcolormap = grmip->nextcolormap; - if (grmip->grInfo.data) Z_Free(grmip->grInfo.data); - free(grmip); + // Confusing at first, but pat->mipmap->nextcolormap + // at the beginning of the loop is the first colormap + // from the linked list of colormaps. + GLMipmap_t *next = NULL; + + // No mipmap in this patch, break out of the loop. + if (!pat->mipmap) + break; + + // No colormap mipmap either. + if (!pat->mipmap->nextcolormap) + break; + + // Set the first colormap to the one that comes after it. + next = pat->mipmap->nextcolormap; + pat->mipmap->nextcolormap = next->nextcolormap; + + // Free image data from memory. + if (next->grInfo.data) + Z_Free(next->grInfo.data); + + // Free the old colormap from memory. + free(next); } } @@ -503,7 +528,7 @@ void HWR_FreeTextureCache(void) // Alam: free the Z_Blocks before freeing it's users - // free all skin after each level: must be done after pfnClearMipMapCache! + // free all patch colormaps after each level: must be done after ClearMipMapCache! for (i = 0; i < numwadfiles; i++) M_AATreeIterate(wadfiles[i]->hwrcache, FreeMipmapColormap); From e3c42b3ba2e764042417d97317856d814742ae02 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 29 Mar 2024 23:48:33 +0100 Subject: [PATCH 2/9] add more safety --- src/hardware/hw_cache.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 35472b85..5d03c416 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -481,7 +481,7 @@ static void FreeMipmapColormap(INT32 patchnum, void *patch) { GLPatch_t* const pat = patch; (void)patchnum; //unused - + // The patch must be valid, obviously if (!pat) return; @@ -498,19 +498,23 @@ static void FreeMipmapColormap(INT32 patchnum, void *patch) if (!pat->mipmap) break; - // No colormap mipmap either. + // No colormap mipmaps either. if (!pat->mipmap->nextcolormap) break; // Set the first colormap to the one that comes after it. next = pat->mipmap->nextcolormap; + if (!next) + break; + pat->mipmap->nextcolormap = next->nextcolormap; // Free image data from memory. if (next->grInfo.data) Z_Free(next->grInfo.data); + next->grInfo.data = NULL; - // Free the old colormap from memory. + // Free the old colormap mipmap from memory. free(next); } } From a7164a5d8f1f5088dfc1540638ffb0153f5f6a89 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Tue, 15 Aug 2023 03:28:51 +0200 Subject: [PATCH 3/9] Do music fade callback on main thread Fixes music fades crashing the game sometimes Backport from SRB2 See: https://git.do.srb2.org/STJr/SRB2/-/commit/0aa763df8543cf98eb2ca8da1d3a77e80f3a3119 Credits to Lactozilla --- src/sdl/mixer_sound.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index c5650192..b2f6ec50 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -90,6 +90,7 @@ static UINT32 fading_timer; static UINT32 fading_duration; static INT32 fading_id; static void (*fading_callback)(void); +static boolean fading_do_callback; #ifdef HAVE_LIBGME static Music_Emu *gme; @@ -106,6 +107,7 @@ static void var_cleanup(void) is_fading = false; fading_callback = NULL; + fading_do_callback = false; internal_volume = 100; } @@ -202,6 +204,13 @@ void I_ShutdownSound(void) void I_UpdateSound(void) { + if (fading_do_callback) + { + if (fading_callback) + (*fading_callback)(); + fading_callback = NULL; + fading_do_callback = false; + } } /// ------------------------ @@ -526,9 +535,8 @@ static UINT32 get_adjusted_position(UINT32 position) static void do_fading_callback(void) { - if (fading_callback) - (*fading_callback)(); - fading_callback = NULL; + // TODO: Should I use a mutex here or something? + fading_do_callback = true; } /// ------------------------ From a68a1d7ef92aba9ac25389927bc2a3ef54854053 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 21 Nov 2023 15:23:03 +0100 Subject: [PATCH 4/9] fix broken resynch text --- src/hu_stuff.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 60b1d14d..a639b5a8 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -1116,6 +1116,10 @@ void HU_Ticker(void) } if (cechotimer > 0) --cechotimer; + + // Animate the desynch dots + if (hu_resynching) + resynch_ticker++; //tic tic tic tic tic HU_TickSongCredits(); } From 3485c116c83a575a3125360aeba6702e87fcdf1b Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 21 Nov 2023 15:25:40 +0100 Subject: [PATCH 5/9] run P_RunShadows also in preticker so the game wont crash randomly at mapload sometimes --- src/p_tick.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/p_tick.c b/src/p_tick.c index 45fefa81..90ae479d 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -895,6 +895,8 @@ void P_PreTicker(INT32 frames) // Run shield positioning //P_RunShields(); P_RunOverlays(); + + P_RunShadows(); P_UpdateSpecials(); P_RespawnSpecials(); From 3dce66a5c55bd7495e52f15020e3210c367f17a5 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 21 Nov 2023 15:27:46 +0100 Subject: [PATCH 6/9] fix ping command showing a random players ms ping instead of your ping --- src/d_net.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_net.c b/src/d_net.c index 8fa218cd..1dcbb379 100644 --- a/src/d_net.c +++ b/src/d_net.c @@ -1464,7 +1464,7 @@ void Command_Ping_f(void) if (!server && playeringame[consoleplayer]) { - CONS_Printf("\nYour ping is %d frames (%d ms)\n", playerpingtable[consoleplayer], (INT32)(playerpingtable[i] * (1000.00f / TICRATE))); + CONS_Printf("\nYour ping is %d frames (%d ms)\n", playerpingtable[consoleplayer], (INT32)(playerpingtable[consoleplayer] * (1000.00f / TICRATE))); } } From 2172c9ddb29cd2bcc5fe06b6483305291aac84a6 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 30 Mar 2024 00:04:42 +0100 Subject: [PATCH 7/9] fix overflow check overflowing in R_DrawRepeatMaskedColumn fixes renderer lock ups with transparent textures in software renderer --- src/r_segs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r_segs.c b/src/r_segs.c index c531be52..d3fa1c19 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -681,7 +681,7 @@ static void R_DrawRepeatMaskedColumn(column_t *col) { while (sprtopscreen < sprbotscreen) { R_DrawMaskedColumn(col); - if ((INT64)sprtopscreen + dc_texheight*spryscale > (INT64)INT32_MAX) // prevent overflow + if (sprtopscreen + (INT64)dc_texheight*spryscale > (INT64)INT32_MAX) // prevent overflow sprtopscreen = INT32_MAX; else sprtopscreen += dc_texheight*spryscale; From 64f91846af331f28e07c7045661f10b5fd150090 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 30 Mar 2024 00:09:22 +0100 Subject: [PATCH 8/9] Fix Weather Z coordinate not being interpolated in OpenGL makes precip smooth like software --- src/hardware/hw_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 86dd7c34..88f92dbb 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -4538,7 +4538,7 @@ void HWR_ProjectPrecipitationSprite(precipmobj_t *thing) #endif // set top/bottom coords - vis->ty = FIXED_TO_FLOAT(thing->z + spritecachedinfo[lumpoff].topoffset); + vis->ty = FIXED_TO_FLOAT(interp.z + spritecachedinfo[lumpoff].topoffset); vis->precip = true; } From 17e24bb8e294e4ff2dd5f13cac87219d7f76207c Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 30 Mar 2024 00:14:48 +0100 Subject: [PATCH 9/9] Fix OGL shearing visually breaking when looking 90 degrees up or down --- src/r_fps.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/r_fps.c b/src/r_fps.c index 9cbee9c0..7b23ce6d 100644 --- a/src/r_fps.c +++ b/src/r_fps.c @@ -23,6 +23,10 @@ #include "z_zone.h" #include "console.h" // con_startup_loadprogress +#ifdef HWRENDER +#include "hardware/hw_main.h" // for cv_grshearing +#endif + static CV_PossibleValue_t fpscap_cons_t[] = { #ifdef DEVELOP // Lower values are actually pretty useful for debugging interp problems! @@ -119,7 +123,11 @@ static void R_SetupFreelook(player_t *player, boolean skybox) // clip it in the case we are looking a hardware 90 degrees full aiming // (lmps, network and use F12...) - if (rendermode == render_soft) + if (rendermode == render_soft +#ifdef HWRENDER + || (rendermode == render_opengl && cv_grshearing.value) +#endif + ) { G_SoftwareClipAimingPitch((INT32 *)&aimingangle); }