Don't free PU_HWRCACHE and PU_HWRCACHE_UNLOCKED memory tags in HWR_ClearAllTextures.

Probably fixes a random annoying crash around that function.
(I was also suspecting renderer switching was doing other slightly weird stuff.)
This commit is contained in:
Jaime Passos 2020-10-15 14:31:16 -03:00
parent 060c25c14d
commit 70ada935ec
5 changed files with 43 additions and 47 deletions

View File

@ -674,11 +674,6 @@ void HWR_ClearAllTextures(void)
// free references to the textures
HWD.pfnClearMipMapCache();
// free all hardware-converted graphics cached in the heap
// our gool is only the textures since user of the texture is the texture cache
Z_FreeTag(PU_HWRCACHE);
Z_FreeTag(PU_HWRCACHE_UNLOCKED);
// Alam: free the Z_Blocks before freeing it's users
HWR_FreePatchCache(true);
}

View File

@ -108,8 +108,6 @@ void HWR_InitMapTextures(void);
void HWR_LoadMapTextures(size_t pnumtextures);
void HWR_FreeMapTextures(void);
extern boolean gl_maptexturesloaded;
patch_t *HWR_GetCachedGLPatchPwad(UINT16 wad, UINT16 lump);
patch_t *HWR_GetCachedGLPatch(lumpnum_t lumpnum);

View File

@ -163,9 +163,11 @@ int rs_hw_numcolors = 0;
int rs_hw_batchsorttime = 0;
int rs_hw_batchdrawtime = 0;
boolean gl_init = false;
boolean gl_maploaded = false;
boolean gl_sessioncommandsadded = false;
boolean gl_shadersavailable = true;
// ==========================================================================
// Lighting
// ==========================================================================
@ -6113,6 +6115,33 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player)
HWD.pfnGClipRect(0, 0, vid.width, vid.height, NZCLIP_PLANE);
}
void HWR_LoadLevel(void)
{
// Lactozilla (December 8, 2019)
// Level setup used to free EVERY mipmap from memory.
// Even mipmaps that aren't related to level textures.
// Presumably, the hardware render code used to store textures as level data.
// Meaning, they had memory allocated and marked with the PU_LEVEL tag.
// Level textures are only reloaded after R_LoadTextures, which is
// when the texture list is loaded.
// Sal: Unfortunately, NOT freeing them causes the dreaded Color Bug.
HWR_FreeColormapCache();
#ifdef ALAM_LIGHTING
// BP: reset light between levels (we draw preview frame lights on current frame)
HWR_ResetLights();
#endif
HWR_CreatePlanePolygons((INT32)numnodes - 1);
// Build the sky dome
HWR_ClearSkyDome();
HWR_BuildSkyDome();
gl_maploaded = true;
}
// ==========================================================================
// 3D ENGINE COMMANDS
// ==========================================================================
@ -6206,13 +6235,10 @@ void HWR_AddCommands(void)
void HWR_AddSessionCommands(void)
{
static boolean alreadycalled = false;
if (alreadycalled)
if (gl_sessioncommandsadded)
return;
CV_RegisterVar(&cv_glanisotropicmode);
alreadycalled = true;
gl_sessioncommandsadded = true;
}
// --------------------------------------------------------------------------
@ -6220,10 +6246,7 @@ void HWR_AddSessionCommands(void)
// --------------------------------------------------------------------------
void HWR_Startup(void)
{
static boolean startupdone = false;
// do this once
if (!startupdone)
if (!gl_init)
{
INT32 i;
CONS_Printf("HWR_Startup()...\n");
@ -6246,7 +6269,7 @@ void HWR_Startup(void)
if (rendermode == render_opengl)
textureformat = patchformat = GL_TEXFMT_RGBA;
startupdone = true;
gl_init = true;
}
// --------------------------------------------------------------------------
@ -6255,7 +6278,8 @@ void HWR_Startup(void)
void HWR_Switch(void)
{
// Add session commands
HWR_AddSessionCommands();
if (!gl_sessioncommandsadded)
HWR_AddSessionCommands();
// Set special states from CVARs
HWD.pfnSetSpecialState(HWD_SET_TEXTUREFILTERMODE, cv_glfiltermode.value);
@ -6266,7 +6290,7 @@ void HWR_Switch(void)
HWR_LoadMapTextures(numtextures);
// Create plane polygons
if (gamestate == GS_LEVEL || (gamestate == GS_TITLESCREEN && titlemapinaction))
if (!gl_maploaded && (gamestate == GS_LEVEL || (gamestate == GS_TITLESCREEN && titlemapinaction)))
HWR_LoadLevel();
}

View File

@ -123,6 +123,10 @@ extern int rs_hw_numcolors;
extern int rs_hw_batchsorttime;
extern int rs_hw_batchdrawtime;
extern boolean gl_init;
extern boolean gl_maploaded;
extern boolean gl_maptexturesloaded;
extern boolean gl_sessioncommandsadded;
extern boolean gl_shadersavailable;
#endif

View File

@ -4144,6 +4144,8 @@ boolean P_LoadLevel(boolean fromnetsave)
P_SpawnPrecipitation();
#ifdef HWRENDER // not win32 only 19990829 by Kin
gl_maploaded = false;
// Lactozilla: Free extrasubsectors regardless of renderer.
HWR_FreeExtraSubsectors();
@ -4231,33 +4233,6 @@ boolean P_LoadLevel(boolean fromnetsave)
return true;
}
#ifdef HWRENDER
void HWR_LoadLevel(void)
{
// Lactozilla (December 8, 2019)
// Level setup used to free EVERY mipmap from memory.
// Even mipmaps that aren't related to level textures.
// Presumably, the hardware render code used to store textures as level data.
// Meaning, they had memory allocated and marked with the PU_LEVEL tag.
// Level textures are only reloaded after R_LoadTextures, which is
// when the texture list is loaded.
// Sal: Unfortunately, NOT freeing them causes the dreaded Color Bug.
HWR_FreeColormapCache();
#ifdef ALAM_LIGHTING
// BP: reset light between levels (we draw preview frame lights on current frame)
HWR_ResetLights();
#endif
HWR_CreatePlanePolygons((INT32)numnodes - 1);
// Build the sky dome
HWR_ClearSkyDome();
HWR_BuildSkyDome();
}
#endif
//
// P_RunSOC
//