mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 07:11:41 +00:00
[glsl] Fix a pile of memory leaks
For the most part harmless, but fixing the leaks has been uncovering bugs.
This commit is contained in:
parent
e2640d51a7
commit
9ad4f57348
29 changed files with 151 additions and 8 deletions
|
@ -73,6 +73,7 @@ void glsl_R_DrawWaterSurfaces (void);
|
|||
void glsl_R_RegisterTextures (struct model_s **models, int num_models);
|
||||
void glsl_R_BuildDisplayLists (struct model_s **models, int num_models);
|
||||
void glsl_R_InitBsp (void);
|
||||
void glsl_R_ShutdownBsp (void);
|
||||
void glsl_R_LoadSkys (const char *sky);
|
||||
|
||||
#endif//__QF_GLSL_qf_bsp_h
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
#define BLOCK_WIDTH 64
|
||||
#define BLOCK_HEIGHT 64
|
||||
|
||||
void glsl_lightmap_init (void);
|
||||
void glsl_Lightmap_Shutdown (void);
|
||||
struct transform_s;
|
||||
void glsl_R_BuildLightmaps (struct model_s **models, int num_models);
|
||||
void glsl_R_CalcLightmaps (void);
|
||||
|
|
|
@ -42,5 +42,6 @@ struct psystem_s;
|
|||
void glsl_R_DrawParticles (struct psystem_s *psystem);
|
||||
void glsl_R_Particles_Init_Cvars (void);
|
||||
void glsl_R_InitParticles (void);
|
||||
void glsl_R_ShutdownParticles (void);
|
||||
|
||||
#endif//__QF_GLSL_qf_particles_h
|
||||
|
|
|
@ -46,6 +46,7 @@ extern int glsl_palette;
|
|||
extern int glsl_colormap;
|
||||
|
||||
void GLSL_Init_Common (void);
|
||||
void GLSL_Shutdown_Common (void);
|
||||
|
||||
int GLSL_CompileShader (const char *name, const shader_t *shader, int type);
|
||||
int GLSL_LinkProgram (const char *name, int vert, int frag);
|
||||
|
@ -62,6 +63,7 @@ void GLSL_DumpAttribArrays (void);
|
|||
\return 0 for failure, 1 for success.
|
||||
*/
|
||||
int GLSL_RegisterEffect (const char *name, const char *src);
|
||||
void GLSL_ShaderShutdown (void);
|
||||
|
||||
/* Build a shader program script from a list of effect keys.
|
||||
|
||||
|
|
|
@ -151,6 +151,7 @@ Entity_Transform (entity_t ent)
|
|||
|
||||
struct mod_brush_s;
|
||||
void R_AddEfrags (struct mod_brush_s *, entity_t ent);
|
||||
void R_ShutdownEfrags (void);
|
||||
void R_ClearEfragChain (efrag_t *ef);
|
||||
|
||||
///@}
|
||||
|
|
|
@ -34,6 +34,7 @@ struct transform_s;
|
|||
struct tex_s;
|
||||
|
||||
void SCR_Init (void);
|
||||
void SCR_Shutdown (void);
|
||||
|
||||
typedef void (*SCR_Func)(void);
|
||||
// scr_funcs is a null terminated array
|
||||
|
|
|
@ -105,6 +105,7 @@ void Mod_LoadAliasModel (model_t *mod, void *buffer,
|
|||
void Mod_LoadSpriteModel (model_t *mod, void *buffer);
|
||||
|
||||
void Skin_Init (void);
|
||||
void Skin_Shutdown (void);
|
||||
void Skin_Free (skin_t *skin);
|
||||
skin_t *Skin_SetColormap (skin_t *skin, int cmap);
|
||||
skin_t *Skin_SetSkin (skin_t *skin, int cmap, const char *skinname);
|
||||
|
|
|
@ -29,6 +29,7 @@ void R_LineGraph (int x, int y, int *h_vals, int count, int height);
|
|||
|
||||
void gl_R_Init (void);
|
||||
void glsl_R_Init (void);
|
||||
void glsl_R_Shutdown (void);
|
||||
void sw_R_Init (void);
|
||||
void R_RenderFrame (SCR_Func *scr_funcs);
|
||||
void R_Init_Cvars (void);
|
||||
|
|
|
@ -9,6 +9,7 @@ typedef struct GL_context *GL_context;
|
|||
typedef struct gl_ctx_s {
|
||||
GL_context context;
|
||||
void (*load_gl) (void);
|
||||
void (*unload_gl) (struct gl_ctx_s *ctx);
|
||||
void (*choose_visual) (struct gl_ctx_s *ctx);
|
||||
void (*create_context) (struct gl_ctx_s *ctx, int core);
|
||||
void (*init_gl) (void);
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
typedef struct vid_system_s {
|
||||
void (*init) (byte *palette, byte *colormap);
|
||||
void (*shutdown) (void);
|
||||
void (*set_palette) (byte *palette, byte *colormap);
|
||||
void (*init_cvars) (void);
|
||||
void (*update_fullscreen) (int fullscreen);
|
||||
|
|
|
@ -85,6 +85,7 @@ glsl_iqm_clear (model_t *mod, void *data)
|
|||
GLSL_ReleaseTexture (glsl->textures[i]);
|
||||
GLSL_ReleaseTexture (glsl->normmaps[i]);
|
||||
}
|
||||
free (glsl->textures);
|
||||
free (glsl);
|
||||
Mod_FreeIQM (iqm);
|
||||
}
|
||||
|
|
|
@ -255,6 +255,12 @@ Skin_Init (void)
|
|||
m_funcs->Skin_InitTranslations ();
|
||||
}
|
||||
|
||||
void
|
||||
Skin_Shutdown (void)
|
||||
{
|
||||
Hash_DelTable (skin_cache);
|
||||
}
|
||||
|
||||
VISIBLE int
|
||||
Skin_CalcTopColors (byte *out, const byte *in, size_t pixels, int stride)
|
||||
{
|
||||
|
|
|
@ -95,6 +95,16 @@ R_ClearEfrags (void)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
R_ShutdownEfrags (void)
|
||||
{
|
||||
while (efrag_list) {
|
||||
t_efrag_list *efl = efrag_list->next;
|
||||
free (efrag_list);
|
||||
efrag_list = efl;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
R_ClearEfragChain (efrag_t *ef)
|
||||
{
|
||||
|
|
|
@ -1350,6 +1350,13 @@ glsl_R_InitBsp (void)
|
|||
GLSL_FreeShader (frag_shader);
|
||||
}
|
||||
|
||||
void
|
||||
glsl_R_ShutdownBsp (void)
|
||||
{
|
||||
free (r_texture_chains);
|
||||
r_texture_chains = 0;
|
||||
}
|
||||
|
||||
static inline __attribute__((const)) int
|
||||
is_pow2 (unsigned x)
|
||||
{
|
||||
|
|
|
@ -483,6 +483,26 @@ glsl_Draw_Init (void)
|
|||
Cvar_Register (&glsl_conback_texnum_cvar, 0, 0);
|
||||
}
|
||||
|
||||
void
|
||||
glsl_Draw_Shutdown (void)
|
||||
{
|
||||
pic_free (conchars);
|
||||
pic_free (crosshair_pic);
|
||||
if (backtile_pic != white_pic) {
|
||||
pic_free (backtile_pic);
|
||||
}
|
||||
pic_free (white_pic);
|
||||
|
||||
dstring_delete (draw_queue);
|
||||
dstring_delete (line_queue);
|
||||
dstring_delete (glyph_queue);
|
||||
|
||||
Hash_DelTable (pic_cache);
|
||||
|
||||
GLSL_DestroyScrap (draw_scrap);
|
||||
DARRAY_CLEAR (&glsl_fonts);
|
||||
}
|
||||
|
||||
static inline void
|
||||
queue_character (int x, int y, byte chr)
|
||||
{
|
||||
|
|
|
@ -264,3 +264,12 @@ glsl_R_FlushLightmaps (void)
|
|||
{
|
||||
GLSL_ScrapFlush (light_scrap);
|
||||
}
|
||||
|
||||
void
|
||||
glsl_Lightmap_Shutdown (void)
|
||||
{
|
||||
if (light_scrap) {
|
||||
GLSL_DestroyScrap (light_scrap);
|
||||
}
|
||||
free (blocklights);
|
||||
}
|
||||
|
|
|
@ -191,6 +191,18 @@ glsl_R_Init (void)
|
|||
Skin_Init ();
|
||||
}
|
||||
|
||||
void
|
||||
glsl_R_Shutdown (void)
|
||||
{
|
||||
Skin_Shutdown();
|
||||
|
||||
glsl_R_ShutdownParticles ();
|
||||
glsl_Lightmap_Shutdown ();
|
||||
glsl_R_ShutdownBsp ();
|
||||
SCR_Shutdown ();
|
||||
glsl_Draw_Shutdown ();
|
||||
}
|
||||
|
||||
void
|
||||
glsl_R_NewScene (scene_t *scene)
|
||||
{
|
||||
|
|
|
@ -162,6 +162,13 @@ glsl_particles_f (void *data, const cvar_t *cvar)
|
|||
alloc_arrays (&r_psystem);//FIXME
|
||||
}
|
||||
|
||||
void
|
||||
glsl_R_ShutdownParticles (void)
|
||||
{
|
||||
free (particleVertexArray);
|
||||
free (pVAindices);
|
||||
}
|
||||
|
||||
void
|
||||
glsl_R_InitParticles (void)
|
||||
{
|
||||
|
|
|
@ -65,6 +65,21 @@ effect_get_key (const void *e, void *unused)
|
|||
return effect->name;
|
||||
}
|
||||
|
||||
static void
|
||||
effect_free (void *e, void *unused)
|
||||
{
|
||||
glsl_effect_t *effect = e;
|
||||
free ((char *) effect->name);
|
||||
Segtext_delete (effect->text);
|
||||
}
|
||||
|
||||
void
|
||||
GLSL_ShaderShutdown (void)
|
||||
{
|
||||
Hash_DelTable (effect_tab);
|
||||
ALLOC_FREE_BLOCKS (effects);
|
||||
}
|
||||
|
||||
int
|
||||
GLSL_RegisterEffect (const char *name, const char *src)
|
||||
{
|
||||
|
@ -72,7 +87,7 @@ GLSL_RegisterEffect (const char *name, const char *src)
|
|||
segtext_t *text;
|
||||
|
||||
if (!effect_tab)
|
||||
effect_tab = Hash_NewTable (61, effect_get_key, 0, 0, 0);
|
||||
effect_tab = Hash_NewTable (61, effect_get_key, effect_free, 0, 0);
|
||||
|
||||
if (Hash_Find (effect_tab, name)) {
|
||||
Sys_Printf ("WARNING: ignoring duplicate '%s' effect\n", name);
|
||||
|
|
|
@ -142,6 +142,12 @@ GLSL_SetPalette (void *data, const byte *palette)
|
|||
free (pal);
|
||||
}
|
||||
|
||||
void
|
||||
GLSL_Shutdown_Common (void)
|
||||
{
|
||||
GLSL_ShaderShutdown ();
|
||||
}
|
||||
|
||||
void
|
||||
GLSL_Init_Common (void)
|
||||
{
|
||||
|
|
|
@ -76,6 +76,8 @@ static U void (*const r_scrapdelete)(rscrap_t *) = R_ScrapDelete;
|
|||
static void
|
||||
R_shutdown (void *data)
|
||||
{
|
||||
R_ShutdownEfrags ();
|
||||
R_MaxDlightsCheck (0); // frees memory
|
||||
PI_UnloadPlugin (vidrendmodule);
|
||||
}
|
||||
|
||||
|
|
|
@ -114,7 +114,7 @@ R_MaxDlightsCheck (int max_dlights)
|
|||
if (r_dlights)
|
||||
free (r_dlights);
|
||||
|
||||
r_dlights=0;
|
||||
r_dlights = 0;
|
||||
|
||||
if (r_maxdlights)
|
||||
r_dlights = (dlight_t *) calloc (r_maxdlights, sizeof (dlight_t));
|
||||
|
|
|
@ -491,6 +491,8 @@ bi_draw_destroy (progs_t *pr, void *_res)
|
|||
{
|
||||
draw_resources_t *res = (draw_resources_t *) _res;
|
||||
Hash_DelTable (res->pic_hash);
|
||||
PR_RESDELMAP (res->qpic_map);
|
||||
PR_RESDELMAP (res->charbuff_map);
|
||||
|
||||
free (res);
|
||||
}
|
||||
|
|
|
@ -475,6 +475,12 @@ SCR_Init (void)
|
|||
update_vrect ();
|
||||
}
|
||||
|
||||
void
|
||||
SCR_Shutdown (void)
|
||||
{
|
||||
EntQueue_Delete (r_ent_queue);
|
||||
}
|
||||
|
||||
void
|
||||
SCR_NewScene (scene_t *scene)
|
||||
{
|
||||
|
|
|
@ -112,6 +112,10 @@ glsl_vid_render_init (void)
|
|||
static void
|
||||
glsl_vid_render_shutdown (void)
|
||||
{
|
||||
glsl_R_Shutdown ();
|
||||
GLSL_Shutdown_Common ();
|
||||
|
||||
glsl_ctx->unload_gl (glsl_ctx);
|
||||
}
|
||||
|
||||
static unsigned int GLErr_InvalidEnum;
|
||||
|
|
|
@ -342,8 +342,8 @@ X11_CreateNullCursor (void)
|
|||
return;
|
||||
|
||||
cursormask = XCreatePixmap (x_disp, x_root, 1, 1, 1);
|
||||
xgc.function = GXclear;
|
||||
|
||||
xgc.function = GXclear;
|
||||
gc = XCreateGC (x_disp, cursormask, GCFunction, &xgc);
|
||||
|
||||
XFillRectangle (x_disp, cursormask, gc, 0, 0, 1, 1);
|
||||
|
|
|
@ -316,9 +316,28 @@ VID_OnVidResize_RemoveListener (viddef_listener_t listener, void *data)
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
VID_shutdown (void *data)
|
||||
{
|
||||
if (vid_system.shutdown) {
|
||||
vid_system.shutdown ();
|
||||
}
|
||||
free ((char *) vid_width_cvar.default_value);
|
||||
free ((char *) vid_height_cvar.default_value);
|
||||
free (viddef.gammatable);
|
||||
free (viddef.palette);
|
||||
free (viddef.palette32);
|
||||
|
||||
DARRAY_CLEAR (viddef.onPaletteChanged);
|
||||
DARRAY_CLEAR (viddef.onVidResize);
|
||||
free (viddef.onPaletteChanged);
|
||||
free (viddef.onVidResize);
|
||||
}
|
||||
|
||||
VISIBLE void
|
||||
VID_Init (byte *palette, byte *colormap)
|
||||
{
|
||||
Sys_RegisterShutdown (VID_shutdown, 0);
|
||||
vid_system.init (palette, colormap);
|
||||
}
|
||||
|
||||
|
|
|
@ -82,9 +82,9 @@ D_EndDirectRect (int x, int y, int width, int height)
|
|||
}
|
||||
|
||||
static void
|
||||
VID_shutdown (void *data)
|
||||
X11_VID_Shutdown (void)
|
||||
{
|
||||
Sys_MaskPrintf (SYS_vid, "VID_shutdown\n");
|
||||
Sys_MaskPrintf (SYS_vid, "X11_VID_shutdown\n");
|
||||
X11_CloseDisplay ();
|
||||
}
|
||||
|
||||
|
@ -109,8 +109,6 @@ X11_VID_SetPalette (byte *palette, byte *colormap)
|
|||
static void
|
||||
X11_VID_Init (byte *palette, byte *colormap)
|
||||
{
|
||||
Sys_RegisterShutdown (VID_shutdown, 0);
|
||||
|
||||
vid_internal.gl_context = X11_GL_Context;
|
||||
vid_internal.sw_context = X11_SW_Context;
|
||||
#ifdef HAVE_VULKAN
|
||||
|
@ -153,6 +151,7 @@ X11_VID_Init_Cvars (void)
|
|||
|
||||
vid_system_t vid_system = {
|
||||
.init = X11_VID_Init,
|
||||
.shutdown = X11_VID_Shutdown,
|
||||
.init_cvars = X11_VID_Init_Cvars,
|
||||
.update_fullscreen = X11_UpdateFullscreen,
|
||||
.set_palette = X11_VID_SetPalette,
|
||||
|
|
|
@ -248,11 +248,19 @@ glx_load_gl (void)
|
|||
qfglFinish = QFGL_ProcAddress ("glFinish", true);
|
||||
}
|
||||
|
||||
static void
|
||||
glx_unload_gl (gl_ctx_t *ctx)
|
||||
{
|
||||
dlclose (libgl_handle);
|
||||
free (ctx);
|
||||
}
|
||||
|
||||
gl_ctx_t *
|
||||
X11_GL_Context (void)
|
||||
{
|
||||
gl_ctx_t *ctx = calloc (1, sizeof (gl_ctx_t));
|
||||
ctx->load_gl = glx_load_gl;
|
||||
ctx->unload_gl = glx_unload_gl;
|
||||
ctx->choose_visual = glx_choose_visual;
|
||||
ctx->create_context = glx_create_context;
|
||||
ctx->get_proc_address = QFGL_ProcAddress;
|
||||
|
|
Loading…
Reference in a new issue