Merge branch 'next-lc-uint16' into 'next'

Fix skincolor-related memory leak

See merge request STJr/SRB2!1066
This commit is contained in:
James R 2020-07-16 22:01:07 -04:00
commit 7c2f81e4ed
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);