From 5dfbf7c6e71c9024a7f0448156adcb29366b64b2 Mon Sep 17 00:00:00 2001
From: SmallJoker <mk939@ymail.com>
Date: Mon, 17 Sep 2018 19:57:22 +0200
Subject: [PATCH] Final door toggle crash fix

---
 src/mechanisms.lua | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/mechanisms.lua b/src/mechanisms.lua
index 20fac81..b065c90 100644
--- a/src/mechanisms.lua
+++ b/src/mechanisms.lua
@@ -14,14 +14,16 @@ local function door_toggle(pos_actuator, pos_door, player)
 		minetest.set_node(pos_actuator,
 			{name=actuator.name:gsub("_off", "_on"), param2=actuator.param2})
 	end
-	door:open(player_name)
+	door:open(player)
 
 	minetest.after(2, function()
 		if minetest.get_node(pos_actuator).name:sub(-3) == "_on" then
 			minetest.set_node(pos_actuator,
 				{name=actuator.name, param2=actuator.param2})
 		end
-		door:close(player_name)
+		-- Re-get player object (or nil) because 'player' could
+		-- be an invalid object at this time (player left)
+		door:close(minetest.get_player_by_name(player_name))
 	end)
 end
 
-- 
GitLab