Fix possible nil crashes in mcl_jukebox

This commit is contained in:
Wuzzy 2020-12-21 13:13:01 +01:00
parent fd53198c9a
commit b0dc0ecc9c
1 changed files with 7 additions and 3 deletions

View File

@ -81,7 +81,7 @@ local function now_playing(player, track_id)
if not player or not player:is_player() or not active_huds[playername] or not hud_sequence_numbers[playername] or seq ~= hud_sequence_numbers[playername] then if not player or not player:is_player() or not active_huds[playername] or not hud_sequence_numbers[playername] or seq ~= hud_sequence_numbers[playername] then
return return
end end
if id == active_huds[playername] then if id ~= nil and id == active_huds[playername] then
player:hud_remove(active_huds[playername]) player:hud_remove(active_huds[playername])
active_huds[playername] = nil active_huds[playername] = nil
end end
@ -162,8 +162,10 @@ minetest.register_node("mcl_jukebox:jukebox", {
inv:set_stack("main", 1, "") inv:set_stack("main", 1, "")
if active_tracks[cname] ~= nil then if active_tracks[cname] ~= nil then
minetest.sound_stop(active_tracks[cname]) minetest.sound_stop(active_tracks[cname])
clicker:hud_remove(active_huds[cname])
active_tracks[cname] = nil active_tracks[cname] = nil
end
if active_huds[cname] ~= nil then
clicker:hud_remove(active_huds[cname])
active_huds[cname] = nil active_huds[cname] = nil
end end
else else
@ -219,8 +221,10 @@ minetest.register_node("mcl_jukebox:jukebox", {
dropped_item:set_yaw(math.pi/2) dropped_item:set_yaw(math.pi/2)
if active_tracks[name] ~= nil then if active_tracks[name] ~= nil then
minetest.sound_stop(active_tracks[name]) minetest.sound_stop(active_tracks[name])
digger:hud_remove(active_huds[name])
active_tracks[name] = nil active_tracks[name] = nil
end
if active_huds[name] ~= nil then
digger:hud_remove(active_huds[name])
active_huds[name] = nil active_huds[name] = nil
end end
end end