renders: sync readfile_t type with FS_LoadFile

Usage of FS_LoadFile as readfile_t is unsupported for now as requires
usage FS_FreeFile instead just copy of file content.

Fixes memory leak for sin models load.
This commit is contained in:
Denis Pauk 2024-06-23 13:02:50 +03:00
parent d15bb81e58
commit 6a3859cd9e
7 changed files with 63 additions and 48 deletions

View file

@ -2670,7 +2670,7 @@ Mod_LoadModel_SDEF_Text(const char *mod_name, char *curr_buff, readfile_t read_f
} }
} }
base = (sin_sbm_header_t*)read_file(base_model, &base_size); base_size = read_file(base_model, &base);
if (base_size <= 0) if (base_size <= 0)
{ {
R_Printf(PRINT_DEVELOPER, "%s: %s No base model for %s\n", R_Printf(PRINT_DEVELOPER, "%s: %s No base model for %s\n",
@ -2709,7 +2709,7 @@ Mod_LoadModel_SDEF_Text(const char *mod_name, char *curr_buff, readfile_t read_f
{ {
int anim_size, j; int anim_size, j;
anim[animation_num] = (sin_sam_header_t*)read_file(animations[i], &anim_size); anim_size = read_file(animations[i], &anim[animation_num]);
if (anim_size <= 0) if (anim_size <= 0)
{ {
R_Printf(PRINT_DEVELOPER, "%s: %s empty animation %s\n", R_Printf(PRINT_DEVELOPER, "%s: %s empty animation %s\n",

View file

@ -371,20 +371,23 @@ Mod_LoadBrushModel(model_t *mod, const void *buffer, int modfilelen)
} }
/* Temporary solution, need to use load file dirrectly */ /* Temporary solution, need to use load file dirrectly */
static char * static int
Mod_ReadFile(const char *name, int *size) Mod_ReadFile(const char *path, void **buffer)
{ {
char *buffer, *data; char *data;
int size;
*size = ri.FS_LoadFile(name, (void **)&buffer); size = ri.FS_LoadFile(path, (void **)&data);
if (*size <= 0) if (size <= 0)
{ {
return NULL; return size;
} }
data = malloc(*size); *buffer = malloc(size);
memcpy(data, buffer, *size); memcpy(*buffer, data, size);
return data; ri.FS_FreeFile((void *)data);
return size;
} }
/* /*

View file

@ -372,20 +372,23 @@ Mod_LoadBrushModel(gl3model_t *mod, const void *buffer, int modfilelen)
} }
/* Temporary solution, need to use load file dirrectly */ /* Temporary solution, need to use load file dirrectly */
static char * static int
Mod_ReadFile(const char *name, int *size) Mod_ReadFile(const char *path, void **buffer)
{ {
char *buffer, *data; char *data;
int size;
*size = ri.FS_LoadFile(name, (void **)&buffer); size = ri.FS_LoadFile(path, (void **)&data);
if (*size <= 0) if (size <= 0)
{ {
return NULL; return size;
} }
data = malloc(*size); *buffer = malloc(size);
memcpy(data, buffer, *size); memcpy(*buffer, data, size);
return data; ri.FS_FreeFile((void *)data);
return size;
} }
/* /*

View file

@ -372,20 +372,23 @@ Mod_LoadBrushModel(gl4model_t *mod, const void *buffer, int modfilelen)
} }
/* Temporary solution, need to use load file dirrectly */ /* Temporary solution, need to use load file dirrectly */
static char * static int
Mod_ReadFile(const char *name, int *size) Mod_ReadFile(const char *path, void **buffer)
{ {
char *buffer, *data; char *data;
int size;
*size = ri.FS_LoadFile(name, (void **)&buffer); size = ri.FS_LoadFile(path, (void **)&data);
if (*size <= 0) if (size <= 0)
{ {
return NULL; return size;
} }
data = malloc(*size); *buffer = malloc(size);
memcpy(data, buffer, *size); memcpy(*buffer, data, size);
return data; ri.FS_FreeFile((void *)data);
return size;
} }
/* /*

View file

@ -326,7 +326,7 @@ typedef struct
} bspxlightgrid_t; } bspxlightgrid_t;
/* Shared models func */ /* Shared models func */
typedef char* (*readfile_t)(const char *name, int *size); typedef int (*readfile_t)(const char *path, void **buffer);
typedef struct image_s* (*findimage_t)(const char *name, imagetype_t type); typedef struct image_s* (*findimage_t)(const char *name, imagetype_t type);
extern void *Mod_LoadModel(const char *mod_name, const void *buffer, int modfilelen, extern void *Mod_LoadModel(const char *mod_name, const void *buffer, int modfilelen,
vec3_t mins, vec3_t maxs, struct image_s ***skins, int *numskins, vec3_t mins, vec3_t maxs, struct image_s ***skins, int *numskins,

View file

@ -379,20 +379,23 @@ Mod_LoadBrushModel(model_t *mod, const void *buffer, int modfilelen)
} }
/* Temporary solution, need to use load file dirrectly */ /* Temporary solution, need to use load file dirrectly */
static char * static int
Mod_ReadFile(const char *name, int *size) Mod_ReadFile(const char *path, void **buffer)
{ {
char *buffer, *data; char *data;
int size;
*size = ri.FS_LoadFile(name, (void **)&buffer); size = ri.FS_LoadFile(path, (void **)&data);
if (*size <= 0) if (size <= 0)
{ {
return NULL; return size;
} }
data = malloc(*size); *buffer = malloc(size);
memcpy(data, buffer, *size); memcpy(*buffer, data, size);
return data; ri.FS_FreeFile((void *)data);
return size;
} }
/* /*

View file

@ -346,20 +346,23 @@ Mod_LoadBrushModel(model_t *mod, const void *buffer, int modfilelen)
} }
/* Temporary solution, need to use load file dirrectly */ /* Temporary solution, need to use load file dirrectly */
static char * static int
Mod_ReadFile(const char *name, int *size) Mod_ReadFile(const char *path, void **buffer)
{ {
char *buffer, *data; char *data;
int size;
*size = ri.FS_LoadFile(name, (void **)&buffer); size = ri.FS_LoadFile(path, (void **)&data);
if (*size <= 0) if (size <= 0)
{ {
return NULL; return size;
} }
data = malloc(*size); *buffer = malloc(size);
memcpy(data, buffer, *size); memcpy(*buffer, data, size);
return data; ri.FS_FreeFile((void *)data);
return size;
} }
/* /*