From 1f811e631052acaba11f5c05e82f00d6688b330a Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Thu, 12 May 2022 22:49:48 +0900 Subject: [PATCH] [nq] Fix a particularly nasty memory leak Nasty because it was caused by spaghetti (normally, I like the stuff). Drinking-age spaghetti at that. Nicely, this removes the need for one function in sv_ded.c (which is what I think I was trying to achieve). --- nq/source/cl_main.c | 42 +++++++++++++++++++----------------------- nq/source/host.c | 1 - nq/source/sv_ded.c | 5 ----- 3 files changed, 19 insertions(+), 29 deletions(-) diff --git a/nq/source/cl_main.c b/nq/source/cl_main.c index c9cf1d66f..3ae1994b5 100644 --- a/nq/source/cl_main.c +++ b/nq/source/cl_main.c @@ -231,9 +231,27 @@ CL_ClearMemory (void) SCR_SetFullscreen (0); cls.signon = 0; + SZ_Clear (&cls.message); + + if (cl.viewstate.weapon_entity) { + Scene_DestroyEntity (cl_world.scene, cl.viewstate.weapon_entity); + } + if (cl.players) { + int i; + + for (i = 0; i < cl.maxclients; i++) + Info_Destroy (cl.players[i].userinfo); + } + // wipe the entire cl structure __auto_type cam = cl.viewstate.camera_transform; memset (&cl, 0, sizeof (cl)); cl.viewstate.camera_transform = cam; + + CL_ClearTEnts (); + + SCR_NewScene (0); + + CL_ClearEnts (); } void @@ -267,24 +285,10 @@ CL_InitCvars (void) void CL_ClearState (void) { + CL_ClearMemory (); if (!sv.active) Host_ClearMemory (); - if (cl.viewstate.weapon_entity) { - Scene_DestroyEntity (cl_world.scene, cl.viewstate.weapon_entity); - } - if (cl.players) { - int i; - - for (i = 0; i < cl.maxclients; i++) - Info_Destroy (cl.players[i].userinfo); - } - - // wipe the entire cl structure - __auto_type cam = cl.viewstate.camera_transform; - memset (&cl, 0, sizeof (cl)); - cl.viewstate.camera_transform = cam; - cl.viewstate.player_origin = (vec4f_t) {0, 0, 0, 1}; cl.viewstate.chase = 1; cl.viewstate.chasestate = &cl.chasestate; @@ -293,14 +297,6 @@ CL_ClearState (void) SCR_SetFullscreen (0); r_data->lightstyle = cl.lightstyle; - SZ_Clear (&cls.message); - - CL_ClearTEnts (); - - SCR_NewScene (0); - - CL_ClearEnts (); - cl.viewstate.weapon_entity = Scene_CreateEntity (cl_world.scene); CL_Init_Entity (cl.viewstate.weapon_entity); r_data->view_model = cl.viewstate.weapon_entity; diff --git a/nq/source/host.c b/nq/source/host.c index f79b29856..4f42cdec4 100644 --- a/nq/source/host.c +++ b/nq/source/host.c @@ -627,7 +627,6 @@ void Host_ClearMemory (void) { Sys_MaskPrintf (SYS_dev, "Clearing memory\n"); - CL_ClearMemory (); Mod_ClearAll (); if (host_hunklevel) Hunk_FreeToLowMark (0, host_hunklevel); diff --git a/nq/source/sv_ded.c b/nq/source/sv_ded.c index fd0741a7c..167596e74 100644 --- a/nq/source/sv_ded.c +++ b/nq/source/sv_ded.c @@ -72,11 +72,6 @@ CL_UpdateScreen (double realtime) { } -void -CL_ClearMemory (void) -{ -} - void CL_Cmd_ForwardToServer (void) {