From 608e236d90473a8f3313f2fb8b84c79d849dc2e9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gustaf=20Alh=C3=A4ll?= <gustaf@hanicef.me>
Date: Sat, 7 Dec 2024 23:11:59 +0100
Subject: [PATCH] Fix segfault when accessing skin from lua on a delayed
 removal

---
 src/lua_mobjlib.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/lua_mobjlib.c b/src/lua_mobjlib.c
index ebe995ea8c..6bdebf774d 100644
--- a/src/lua_mobjlib.c
+++ b/src/lua_mobjlib.c
@@ -198,12 +198,12 @@ static int mobj_get(lua_State *L)
 	enum mobj_e field = Lua_optoption(L, 2, -1, mobj_fields_ref);
 	lua_settop(L, 2);
 
-	if (!mo || !ISINLEVEL) {
+	if (P_MobjWasRemoved(mo) || !ISINLEVEL) {
 		if (field == mobj_valid) {
 			lua_pushboolean(L, 0);
 			return 1;
 		}
-		if (!mo) {
+		if (P_MobjWasRemoved(mo)) {
 			return LUA_ErrInvalid(L, "mobj_t");
 		} else
 			return luaL_error(L, "Do not access an mobj_t field outside a level!");
-- 
GitLab