From 1a5f457a1c4a4a78fc3eaf380030342abbfe86be Mon Sep 17 00:00:00 2001
From: John FrostFox <john.frostfox@gmail.com>
Date: Fri, 5 Nov 2021 22:46:22 +0300
Subject: [PATCH] Netsave loading crash fix and a bit of optimization

---
 src/p_saveg.c     | 6 ++++++
 src/p_savenetrb.c | 5 +++--
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/p_saveg.c b/src/p_saveg.c
index 995b528fa..73035f963 100755
--- a/src/p_saveg.c
+++ b/src/p_saveg.c
@@ -35,6 +35,7 @@
 #include "lua_script.h"
 #include "p_setup.h"
 #include "p_slopes.h"
+#include "hashtable.h" //I don't want to use hashtables there, but there will be anyways in the future
 
 savedata_t savedata;
 UINT8 *save_p;
@@ -2536,6 +2537,8 @@ static void P_NetArchiveThinkers(void)
 			if (!(th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed
 			 || th->function.acp1 == (actionf_p1)P_NullPrecipThinker))
 				numsaved++;
+			else
+				continue;
 
 			if (th->function.acp1 == (actionf_p1)P_MobjThinker)
 			{
@@ -5544,6 +5547,9 @@ boolean P_LoadGame(INT16 mapoverride)
 
 boolean P_LoadNetGame(boolean reloading)
 {
+	mobjnum_ht_linkedList_Init(); //clean up hashtables to avoid lua stuff using them
+								  //this is temporary and will be rewritten to use in vanilla code
+								  //once rollback netcode will be stable
 	CV_LoadNetVars(&save_p);
 	if (!P_NetUnArchiveMisc(reloading))
 		return false;
diff --git a/src/p_savenetrb.c b/src/p_savenetrb.c
index 1a186da5f..c8bc0a35c 100755
--- a/src/p_savenetrb.c
+++ b/src/p_savenetrb.c
@@ -2636,6 +2636,8 @@ static void P_NetArchiveThinkers(void)
 			if (!(th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed
 			 || th->function.acp1 == (actionf_p1)P_NullPrecipThinker))
 				numsaved++;
+			else
+				continue;
 
 			if (th->function.acp1 == (actionf_p1)P_MobjThinker)
 			{
@@ -5882,6 +5884,7 @@ boolean P_LoadGameState(const savestate_t* savestate)
     INT16 savedGameMap;
 	precise_t currentTime;
 	loadStateBenchmark = I_GetPreciseTime();
+	mobjnum_ht_linkedList_Init();
 	if (savestate->buffer == NULL)
 	{
 		loadStateBenchmark = I_GetPreciseTime() - loadStateBenchmark;
@@ -5900,8 +5903,6 @@ boolean P_LoadGameState(const savestate_t* savestate)
 		return false;
 	}
 
-	mobjnum_ht_linkedList_Init();
-
 	globalmobjnum = READUINT32(save_p);
 
 	con_muted = true;
-- 
GitLab