From 3d14d155e08090c4e13f95072ba8846a5c101ad9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gustaf=20Alh=C3=A4ll?= <gustaf@hanicef.me>
Date: Sat, 12 Aug 2023 12:31:59 +0200
Subject: [PATCH] Fix segfault when spectating on an Emerald Hunt map

---
 src/st_stuff.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/st_stuff.c b/src/st_stuff.c
index c6e6befc62..a6bd77cfae 100644
--- a/src/st_stuff.c
+++ b/src/st_stuff.c
@@ -2512,6 +2512,8 @@ num:
 static INT32 ST_drawEmeraldHuntIcon(mobj_t *hunt, patch_t **patches, INT32 offset)
 {
 	INT32 interval, i;
+	if (stplyr->mo == NULL)
+		return 0;  // player just joined after spectating, can happen on custom gamemodes.
 	UINT32 dist = ((UINT32)P_AproxDistance(P_AproxDistance(stplyr->mo->x - hunt->x, stplyr->mo->y - hunt->y), stplyr->mo->z - hunt->z))>>FRACBITS;
 
 	if (dist < 128)
-- 
GitLab