Skip to content

Commit 206a59b

Browse files
committed
Fix potential crashes and a memleak
1 parent 26379f8 commit 206a59b

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

mods/apis/ctf_gui/init.lua

+8-2
Original file line numberDiff line numberDiff line change
@@ -460,10 +460,16 @@ function ctf_gui.old_show_formspec(player, formname, formdef)
460460
formdef._info = formdef
461461
context[player] = formdef
462462

463-
minetest.log("action", "Showing formspec "..dump(formname).." to "..dump(player))
464-
minetest.show_formspec(player, formname, formspec)
463+
if minetest.get_player_by_name(player) then
464+
minetest.log("action", "Showing formspec "..dump(formname).." to "..dump(player))
465+
minetest.show_formspec(player, formname, formspec)
466+
end
465467
end,
466468
formdef, ctf_gui.ELEM_SIZE, ctf_gui.SCROLLBAR_WIDTH)
467469
end
468470

471+
minetest.register_on_leaveplayer(function(player)
472+
context[player:get_player_name()] = nil
473+
end)
474+
469475
dofile(minetest.get_modpath("ctf_gui").."/dev.lua")

mods/ctf/ctf_modebase/respawn_delay.lua

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
local RESPAWN_SECONDS = 7
22
local AUTO_RESPAWN_TIME = 0.4
3-
local respawn_delay = {}
3+
local respawn_delay = {--[[
4+
pname = {
5+
obj = <freeze object>,
6+
timer = <minetest.after job>,
7+
timer = <minetest.after job>,
8+
hp_max = <Player's max hp before respawn process started>,
9+
left = <Time left to respawn>,
10+
state = <?>,
11+
}
12+
]]}
413
local hud = mhud.init()
514

615
minetest.register_entity("ctf_modebase:respawn_movement_freezer", {
@@ -132,6 +141,9 @@ minetest.register_on_leaveplayer(function(player)
132141
if respawn_delay[pname].timer then
133142
respawn_delay[pname].timer:cancel()
134143
end
144+
if respawn_delay[pname].autorespawn then
145+
respawn_delay[pname].autorespawn:cancel()
146+
end
135147
player:set_properties({hp_max = respawn_delay[pname].hp_max})
136148
respawn_delay[pname] = nil
137149
end

0 commit comments

Comments
 (0)