From e534f9e2b3ab76d671e803a2ca0e5dbc60cd7d22 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Tue, 10 Sep 2024 01:18:30 +0300 Subject: [PATCH 1/2] filesystem: fix compressed buffer allocation --- src/common/filesystem.c | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/src/common/filesystem.c b/src/common/filesystem.c index 7c0e7b825..975c2561c 100644 --- a/src/common/filesystem.c +++ b/src/common/filesystem.c @@ -726,23 +726,31 @@ int FS_Read(void *buffer, int size, fileHandle_t f) { qboolean tried = false; /* Tried to read from a CD. */ - byte *buf; /* Buffer. */ + byte *buf, *compressed_buf; /* Buffer. */ int r; /* Number of bytes read. */ int remaining; /* Remaining bytes. */ fsHandle_t *handle; /* File handle. */ handle = FS_GetFileByHandle(f); + buf = (byte *)buffer; + compressed_buf = (byte *)buffer; + /* Read. */ if (handle->compressed_size) { remaining = handle->compressed_size; + if (size < handle->compressed_size) + { + /* compressed chunk bigger than provided buffer */ + compressed_buf = malloc(handle->compressed_size); + buf = compressed_buf; + } } else { remaining = size; } - buf = (byte *)buffer; while (remaining) { @@ -784,7 +792,13 @@ FS_Read(void *buffer, int size, fileHandle_t f) buf += r; } - return FS_DecompressFile(buffer, size, handle); + remaining = FS_DecompressFile(compressed_buf, size, handle); + if (buffer != compressed_buf) + { + memcpy(buffer, compressed_buf, size); + free(compressed_buf); + } + return remaining; } /* @@ -795,7 +809,7 @@ int FS_FRead(void *buffer, int size, int count, fileHandle_t f) { qboolean tried = false; /* Tried to read from a CD. */ - byte *buf; /* Buffer. */ + byte *buf, *compressed_buf; /* Buffer. */ int loops; /* Loop indicator. */ int r; /* Number of bytes read. */ int remaining; /* Remaining bytes. */ @@ -806,6 +820,14 @@ FS_FRead(void *buffer, int size, int count, fileHandle_t f) /* Read. */ loops = count; buf = (byte *)buffer; + compressed_buf = (byte *)buffer; + + if (handle->compressed_size && size < handle->compressed_size) + { + /* compressed chunk bigger than provided buffer */ + compressed_buf = malloc(handle->compressed_size); + buf = compressed_buf; + } while (loops) { @@ -861,7 +883,13 @@ FS_FRead(void *buffer, int size, int count, fileHandle_t f) loops--; } - return FS_DecompressFile(buffer, size, handle); + remaining = FS_DecompressFile(compressed_buf, size, handle); + if (buffer != compressed_buf) + { + memcpy(buffer, compressed_buf, size); + free(compressed_buf); + } + return remaining; } /* From 1aadd6e404b8c15222e83dedae7fef50d21c38b4 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Tue, 10 Sep 2024 01:28:43 +0300 Subject: [PATCH 2/2] gl1: free 16to8 convert table on exit --- src/client/refresh/gl1/gl1_main.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/client/refresh/gl1/gl1_main.c b/src/client/refresh/gl1/gl1_main.c index 54d21b002..1f01d2f39 100644 --- a/src/client/refresh/gl1/gl1_main.c +++ b/src/client/refresh/gl1/gl1_main.c @@ -29,12 +29,12 @@ #define NUM_BEAM_SEGS 6 viddef_t vid; -model_t *r_worldmodel; +model_t *r_worldmodel = NULL; float gldepthmin, gldepthmax; -glconfig_t gl_config; -glstate_t gl_state; +glconfig_t gl_config = {0}; +glstate_t gl_state = {0}; image_t *r_notexture; /* use for bad textures */ image_t *r_particletexture; /* little dot for particles */ @@ -1776,6 +1776,11 @@ RI_Shutdown(void) QGL_Shutdown(); R_FreeTemporaryLMBuffer(); + + if (gl_state.d_16to8table) + { + free(gl_state.d_16to8table); + } } static void