From 1821b4f52df7a41bcb500242502079acea0d7378 Mon Sep 17 00:00:00 2001 From: toaster Date: Wed, 31 May 2023 12:49:51 +0100 Subject: [PATCH] P_InitThinkers: Handle several important mobj cleaning tasks in one place, rather than scattered - titlecam.mobj cannot have P_SetTarget applied when initially setting to NULL, as its previous occupant is some unknown region in memory, and modifying the reference count could in fact change some random number or address ANYWHERE IN THE ENTIRE PROGRAM. - So we straight up wipe it rather than referenced-unset it in one place, always, for general tidiness. - Also move skyboxcenterpnts, skyboxviewpnts, and iquetail/iquehead so it's all centralised. --- src/d_player.h | 2 ++ src/f_finale.c | 1 - src/f_finale.h | 3 --- src/k_podium.c | 2 -- src/p_saveg.c | 8 -------- src/p_setup.c | 3 --- src/p_tick.c | 17 +++++++++++++++-- 7 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/d_player.h b/src/d_player.h index e6e306537..975bc010b 100644 --- a/src/d_player.h +++ b/src/d_player.h @@ -435,6 +435,8 @@ struct altview_t INT32 tics; }; +extern altview_t titlemapcam; + // ======================================================================== // PLAYER STRUCTURE // ======================================================================== diff --git a/src/f_finale.c b/src/f_finale.c index aef80562e..14011b1c9 100644 --- a/src/f_finale.c +++ b/src/f_finale.c @@ -1848,7 +1848,6 @@ void F_StartTitleScreen(void) gamestate_t prevwipegamestate = wipegamestate; titlemapinaction = true; - P_SetTarget(&titlemapcam.mobj, NULL); gamemap = titleMapNum+1; maptol = mapheaderinfo[titleMapNum]->typeoflevel; diff --git a/src/f_finale.h b/src/f_finale.h index 4149f111c..56691a847 100644 --- a/src/f_finale.h +++ b/src/f_finale.h @@ -105,9 +105,6 @@ extern UINT16 tttics; extern boolean ttavailable[6]; // Current menu parameters - -extern altview_t titlemapcam; - extern char curbgname[9]; extern SINT8 curfadevalue; extern INT32 curbgcolor; diff --git a/src/k_podium.c b/src/k_podium.c index 46de1eb79..f21196fd3 100644 --- a/src/k_podium.c +++ b/src/k_podium.c @@ -247,8 +247,6 @@ boolean K_StartCeremony(void) && mapheaderinfo[podiumMapNum] && mapheaderinfo[podiumMapNum]->lumpnum != LUMPERROR) { - P_SetTarget(&titlemapcam.mobj, NULL); - gamemap = podiumMapNum+1; maptol = mapheaderinfo[gamemap-1]->typeoflevel; diff --git a/src/p_saveg.c b/src/p_saveg.c index ca03c667f..29a60da87 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -4526,16 +4526,8 @@ static void P_NetUnArchiveThinkers(savebuffer_t *save) } // we don't want the removed mobjs to come back - iquetail = iquehead = 0; P_InitThinkers(); - // Oh my god don't blast random memory with our reference counts. - waypointcap = trackercap = NULL; - for (i = 0; i <= 15; i++) - { - skyboxcenterpnts[i] = skyboxviewpnts[i] = NULL; - } - // clear sector thinker pointers so they don't point to non-existant thinkers for all of eternity for (i = 0; i < numsectors; i++) { diff --git a/src/p_setup.c b/src/p_setup.c index 4153f889a..3df1bd163 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -8291,9 +8291,6 @@ boolean P_LoadLevel(boolean fromnetsave, boolean reloadinggamestate) K_InitDirector(); } - // clear special respawning que - iquehead = iquetail = 0; - // Initialize ACS scripts if (!fromnetsave) { diff --git a/src/p_tick.c b/src/p_tick.c index 7ac0f7742..da4cc46da 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -213,10 +213,23 @@ void Command_CountMobjs_f(void) void P_InitThinkers(void) { UINT8 i; + + for (i = 0; i < NUM_THINKERLISTS; i++) + { + thlist[i].prev = thlist[i].next = &thlist[i]; + } + + iquehead = iquetail = 0; + waypointcap = NULL; trackercap = NULL; - for (i = 0; i < NUM_THINKERLISTS; i++) - thlist[i].prev = thlist[i].next = &thlist[i]; + + titlemapcam.mobj = NULL; + + for (i = 0; i <= 15; i++) + { + skyboxcenterpnts[i] = skyboxviewpnts[i] = NULL; + } } // Adds a new thinker at the end of the list.