From dcf5c4d3bf8ee66d91fd9428eb65e4d4aebc0df6 Mon Sep 17 00:00:00 2001 From: Lactozilla Date: Mon, 15 Jan 2024 02:47:03 -0300 Subject: [PATCH] Cleanup R_GetFlatForTexture --- src/r_textures.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/r_textures.c b/src/r_textures.c index e5e2bf90d..28f37cdae 100644 --- a/src/r_textures.c +++ b/src/r_textures.c @@ -531,11 +531,14 @@ done: UINT8 *R_GetFlatForTexture(size_t texnum) { - texture_t *texture = textures[texnum]; + if (texnum >= (unsigned)numtextures) + return NULL; + texture_t *texture = textures[texnum]; if (texture->flat != NULL) return texture->flat; + // Special case: Textures that are flats don't need to be converted FROM a texture INTO a flat. if (texture->type == TEXTURETYPE_FLAT) { texpatch_t *patch = &texture->patches[0]; @@ -553,13 +556,11 @@ UINT8 *R_GetFlatForTexture(size_t texnum) else #endif texture->flat = pdata; - - return texture->flat; } + else + texture->flat = (UINT8 *)Picture_TextureToFlat(texnum); - texture->flat = (UINT8 *)Picture_TextureToFlat(texnum); - - flatmemory += texture->width + texture->height; + flatmemory += texture->width * texture->height; return texture->flat; }