Fix skincolor-related memory leak

This commit is contained in:
SwitchKaze 2020-07-14 17:09:31 -05:00
parent 34bd0d9fe7
commit 734033250d
4 changed files with 20 additions and 5 deletions

View File

@ -851,6 +851,7 @@ static void readskincolor(MYFILE *f, INT32 num)
if ((tmp = strtok(NULL,",")) == NULL)
break;
}
skincolor_modified[num] = true;
}
else if (fastcmp(word, "INVCOLOR"))
{

View File

@ -26,8 +26,8 @@
#include "lua_libs.h"
#include "lua_hud.h" // hud_running errors
extern CV_PossibleValue_t Color_cons_t[MAXSKINCOLORS+1];
extern void R_FlushTranslationColormapCache(void);
extern CV_PossibleValue_t Color_cons_t[];
extern UINT8 skincolor_modified[];
boolean LUA_CallAction(const char *action, mobj_t *actor);
state_t *astate;
@ -1559,7 +1559,7 @@ static int lib_setSkinColor(lua_State *L)
else
for (j=0; j<COLORRAMPSIZE; j++)
info->ramp[j] = (*((UINT8 **)luaL_checkudata(L, 3, META_COLORRAMP)))[j];
R_FlushTranslationColormapCache();
skincolor_modified[cnum] = true;
} else if (i == 3 || (str && fastcmp(str,"invcolor"))) {
UINT16 v = (UINT16)luaL_checkinteger(L, 3);
if (v >= numskincolors)
@ -1644,7 +1644,7 @@ static int skincolor_set(lua_State *L)
else
for (i=0; i<COLORRAMPSIZE; i++)
info->ramp[i] = (*((UINT8 **)luaL_checkudata(L, 3, META_COLORRAMP)))[i];
R_FlushTranslationColormapCache();
skincolor_modified[info-skincolors] = true;
} else if (fastcmp(field,"invcolor")) {
UINT16 v = (UINT16)luaL_checkinteger(L, 3);
if (v >= numskincolors)
@ -1698,7 +1698,7 @@ static int colorramp_set(lua_State *L)
if (hud_running)
return luaL_error(L, "Do not alter skincolor_t in HUD rendering code!");
colorramp[n] = i;
R_FlushTranslationColormapCache();
skincolor_modified[cnum] = true;
return 0;
}

View File

@ -134,6 +134,7 @@ UINT32 nflatxshift, nflatyshift, nflatshiftup, nflatmask;
#define NUM_PALETTE_ENTRIES 256
static UINT8** translationtablecache[MAXSKINS + 7] = {NULL};
UINT8 skincolor_modified[MAXSKINCOLORS];
CV_PossibleValue_t Color_cons_t[MAXSKINCOLORS+1];
@ -362,6 +363,7 @@ UINT8* R_GetTranslationColormap(INT32 skinnum, skincolornum_t color, UINT8 flags
{
UINT8* ret;
INT32 skintableindex;
INT32 i;
// Adjust if we want the default colormap
switch (skinnum)
@ -385,6 +387,15 @@ UINT8* R_GetTranslationColormap(INT32 skinnum, skincolornum_t color, UINT8 flags
// Get colormap
ret = translationtablecache[skintableindex][color];
// Rebuild the cache if necessary
if (skincolor_modified[color])
{
for (i = 0; i < (INT32)(sizeof(translationtablecache) / sizeof(translationtablecache[0])); i++)
if (translationtablecache[i] && translationtablecache[i][color])
R_GenerateTranslationColormap(translationtablecache[i][color], i>=MAXSKINS ? MAXSKINS-i-1 : i, color);
skincolor_modified[color] = false;
}
}
else ret = NULL;

View File

@ -117,6 +117,9 @@ void R_FlushTranslationColormapCache(void);
UINT16 R_GetColorByName(const char *name);
UINT16 R_GetSuperColorByName(const char *name);
// Color ramp modification should force a recache
extern UINT8 skincolor_modified[];
// Custom player skin translation
void R_InitViewBuffer(INT32 width, INT32 height);
void R_InitViewBorder(void);