Reset pointers to sky textures on map unload/game change

This fixes a crash when loading a skyless map after one with a sky.
( From: https://github.com/Novum/vkQuake/pull/339 )
This commit is contained in:
Andrei Drexler 2021-08-10 01:00:02 +03:00 committed by Ozkan Sezer
parent bd8615c235
commit 3c8611f604
4 changed files with 21 additions and 7 deletions

View file

@ -2201,6 +2201,7 @@ static void COM_Game_f (void)
//clear out and reload appropriate data
Cache_Flush ();
Mod_ResetAll();
Sky_ClearAll();
if (!isDedicated)
{
TexMgr_NewGame ();

View file

@ -208,6 +208,24 @@ void Sky_LoadSkyBox (const char *name)
q_strlcpy(skybox_name, name, sizeof(skybox_name));
}
/*
=================
Sky_ClearAll
Called on map unload/game change to avoid keeping pointers to freed data
=================
*/
void Sky_ClearAll (void)
{
int i;
skybox_name[0] = 0;
for (i=0; i<6; i++)
skybox_textures[i] = NULL;
solidskytexture = NULL;
alphaskytexture = NULL;
}
/*
=================
Sky_NewMap
@ -217,14 +235,7 @@ void Sky_NewMap (void)
{
char key[128], value[4096];
const char *data;
int i;
//
// initially no sky
//
skybox_name[0] = 0;
for (i=0; i<6; i++)
skybox_textures[i] = NULL;
skyfog = r_skyfog.value;
//

View file

@ -396,6 +396,7 @@ void DrawWaterPoly (glpoly_t *p);
void GL_MakeAliasModelDisplayLists (qmodel_t *m, aliashdr_t *hdr);
void Sky_Init (void);
void Sky_ClearAll (void);
void Sky_DrawSky (void);
void Sky_NewMap (void);
void Sky_LoadTexture (texture_t *mt);

View file

@ -541,6 +541,7 @@ void Host_ClearMemory (void)
Con_DPrintf ("Clearing memory\n");
D_FlushCaches ();
Mod_ClearAll ();
Sky_ClearAll();
/* host_hunklevel MUST be set at this point */
Hunk_FreeToLowMark (host_hunklevel);
cls.signon = 0;