From cd7e1258636a161258f945a244b8aee48663f204 Mon Sep 17 00:00:00 2001 From: toaster Date: Sat, 12 Mar 2022 18:00:52 +0000 Subject: [PATCH] Update texturecache user when reallocating # Conflicts: # src/r_textures.c --- src/r_textures.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/r_textures.c b/src/r_textures.c index b48ca9efd..d04935b3e 100644 --- a/src/r_textures.c +++ b/src/r_textures.c @@ -1056,10 +1056,20 @@ static void R_AllocateTextures(INT32 add) // Create brightmap texture table. Z_Realloc(texturebrightmaps, (newtextures + 1) * sizeof(*texturebrightmaps), PU_STATIC, &texturebrightmaps); - for (i = numtextures; i < newtextures; ++i) + for (i = 0; i < numtextures; ++i) + { + // R_FlushTextureCache relies on the user for + // Z_Free, texturecache has been reallocated so the + // user is now garbage memory. + Z_SetUser(texturecache[i], + (void**)&texturecache[i]); + } + + while (i < newtextures) { texturetranslation[i] = i; texturebrightmaps[i] = 0; + i++; } }