Fix FreeMipmapColormap crash

This commit is contained in:
Jaime Passos 2019-11-24 17:37:11 -03:00
parent 23643e05c0
commit c9ff8ec26b

View file

@ -771,18 +771,25 @@ void HWR_InitTextureCache(void)
gr_textures2 = NULL; gr_textures2 = NULL;
} }
// Callback function for HWR_FreeTextureCache. // Callback function for HWR_FreeTextureCache.
static void FreeMipmapColormap(INT32 patchnum, void *patch) static void FreeMipmapColormap(INT32 patchnum, void *patch)
{ {
GLPatch_t* const grpatch = patch; GLPatch_t* const pat = patch;
(void)patchnum; //unused (void)patchnum; //unused
while (grpatch->mipmap->nextcolormap) while (pat->mipmap && pat->mipmap->nextcolormap) // The mipmap must be valid, obviously
{ {
GLMipmap_t *grmip = grpatch->mipmap->nextcolormap; // Confusing at first, but pat->mipmap->nextcolormap
grpatch->mipmap->nextcolormap = grmip->nextcolormap; // at the beginning of the loop is the first colormap
if (grmip->grInfo.data) Z_Free(grmip->grInfo.data); // from the linked list of colormaps
free(grmip); GLMipmap_t *next = pat->mipmap->nextcolormap;
// Set the first colormap
// to the one that comes after it
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);
} }
} }
@ -799,7 +806,7 @@ void HWR_FreeTextureCache(void)
// Alam: free the Z_Blocks before freeing it's users // 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++) for (i = 0; i < numwadfiles; i++)
M_AATreeIterate(wadfiles[i]->hwrcache, FreeMipmapColormap); M_AATreeIterate(wadfiles[i]->hwrcache, FreeMipmapColormap);