From ae2c60722feb45997051c4fad9ace34419f9f2ba Mon Sep 17 00:00:00 2001 From: cora Date: Mon, 14 Feb 2022 21:58:28 +0100 Subject: [PATCH] Fix C stack overflow upon portal destruction Destroying a nether portal could cause a C stack overflow for large portals when not using luajit. This patch defers removal of the "next batch" of portal nodes to the next globalstep via minetest.after. This has the additional bonus of a neat visual effect depending on server conditions. --- mods/ITEMS/mcl_portals/portal_nether.lua | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/mods/ITEMS/mcl_portals/portal_nether.lua b/mods/ITEMS/mcl_portals/portal_nether.lua index 7e23a9f7..bce50038 100644 --- a/mods/ITEMS/mcl_portals/portal_nether.lua +++ b/mods/ITEMS/mcl_portals/portal_nether.lua @@ -93,14 +93,20 @@ local function destroy_nether_portal(pos) return end if orientation == 0 then - check_remove({x = pos.x - 1, y = pos.y, z = pos.z}, 0) - check_remove({x = pos.x + 1, y = pos.y, z = pos.z}, 0) + minetest.after(0,function() + check_remove({x = pos.x - 1, y = pos.y, z = pos.z}, 0) + check_remove({x = pos.x + 1, y = pos.y, z = pos.z}, 0) + end) else - check_remove({x = pos.x, y = pos.y, z = pos.z - 1}, 1) - check_remove({x = pos.x, y = pos.y, z = pos.z + 1}, 1) + minetest.after(0,function() + check_remove({x = pos.x, y = pos.y, z = pos.z - 1}, 1) + check_remove({x = pos.x, y = pos.y, z = pos.z + 1}, 1) + end) end - check_remove({x = pos.x, y = pos.y - 1, z = pos.z}) - check_remove({x = pos.x, y = pos.y + 1, z = pos.z}) + minetest.after(0,function() + check_remove({x = pos.x, y = pos.y - 1, z = pos.z}) + check_remove({x = pos.x, y = pos.y + 1, z = pos.z}) + end) end minetest.register_node("mcl_portals:portal", {