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.
This commit is contained in:
cora 2022-02-14 21:58:28 +01:00 committed by Nils Dagsson Moskopp
parent de9f2479eb
commit ae2c60722f
No known key found for this signature in database
GPG Key ID: A3BC671C35191080
1 changed files with 12 additions and 6 deletions

View File

@ -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", {