From 7f2473ab76dc585a33824095dcdd4d98c52ca340 Mon Sep 17 00:00:00 2001
From: John FrostFox <john.frostfox@gmail.com>
Date: Mon, 18 Oct 2021 16:13:56 +0300
Subject: [PATCH] "Return to titlescreen" crash fix

---
 src/p_savenetrb.c | 4 ++--
 src/p_setup.c     | 5 +++--
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/p_savenetrb.c b/src/p_savenetrb.c
index 3a6d057a9..95622ba88 100755
--- a/src/p_savenetrb.c
+++ b/src/p_savenetrb.c
@@ -5451,7 +5451,7 @@ static inline boolean P_NetUnArchiveMisc(boolean reloading)
 	// if (!P_LoadLevel(true, reloading))
 	// 	return false;
 
-	if ((!reloading || (gamemap != oldMap)) && !P_LoadLevel(false, reloading))
+	if ((!reloading || (gamemap != oldMap)))
 		return false;
 
 	// get the time
@@ -5800,7 +5800,7 @@ void P_SaveGameState(savestate_t* savestate)
 
     if (savestate->buffer == NULL)
 	{
-		savestate->buffer = Z_Malloc(10 * 1024 * 1024, PU_LEVEL, NULL); //ten megabytes?
+		savestate->buffer = Z_Malloc(10 * 1024 * 1024, PU_STATIC, NULL); //ten megabytes?
 	}
 
     save_p = savestate->buffer;
diff --git a/src/p_setup.c b/src/p_setup.c
index 89296c05c..5ac4dc06b 100755
--- a/src/p_setup.c
+++ b/src/p_setup.c
@@ -3980,8 +3980,8 @@ static void P_InitGametype(void)
 boolean P_LoadLevel(boolean fromnetsave, boolean reloadinggamestate)
 {
 	//prevent loading a level when in a simulation
-	if (issimulation)
-		return true;
+	// if (issimulation)
+	// 	return true;
 
 	// use gamemap to get map number.
 	// 99% of the things already did, so.
@@ -4154,6 +4154,7 @@ boolean P_LoadLevel(boolean fromnetsave, boolean reloadinggamestate)
 	Patch_FreeTag(PU_PATCH_LOWPRIORITY);
 	Patch_FreeTag(PU_PATCH_ROTATED);
 	Z_FreeTags(PU_LEVEL, PU_PURGELEVEL - 1);
+	InvalidateSavestates();
 
 	P_InitThinkers();
 	P_InitCachedActions();
-- 
GitLab