From 8c851f07e4aa0910ebb5d1b07d1770d8562020dc Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Thu, 29 Aug 2019 17:44:48 +0200 Subject: [PATCH] Fix potentially dangerous minetest.after calls --- mods/achievements/init.lua | 6 +++--- mods/default/player.lua | 8 +++++--- mods/hunger/init.lua | 8 +++++--- mods/item_drop/init.lua | 6 ++++-- mods/player_skins/init.lua | 2 +- mods/tnt/init.lua | 2 +- mods/village/generate.lua | 6 +----- mods/village/mapgen.lua | 4 ++-- 8 files changed, 22 insertions(+), 20 deletions(-) diff --git a/mods/achievements/init.lua b/mods/achievements/init.lua index 39ef82c..0e264db 100644 --- a/mods/achievements/init.lua +++ b/mods/achievements/init.lua @@ -85,14 +85,14 @@ function achievements.trigger_achievement(player, aname, times) achievements.achievements[name][aname] = -1 minetest.after( 2.0, - function() + function(name, aname) minetest.chat_send_all( minetest.colorize( "#0f0", "*** " .. S("@1 has earned the achievement “@2”.", name, achievements.registered_achievements[aname].title))) - end) + end, name, aname) end delayed_save() @@ -173,7 +173,7 @@ end -- Add callback functions -minetest.after(0, on_load) +minetest.register_on_mods_loaded(on_load) minetest.register_on_shutdown(on_shutdown) diff --git a/mods/default/player.lua b/mods/default/player.lua index 938b634..ffb7bfa 100644 --- a/mods/default/player.lua +++ b/mods/default/player.lua @@ -66,9 +66,11 @@ local function step(dtime) texture = "bubble.png" }) - minetest.after(0.15, function() - minetest.delete_particlespawner(particlespawners[name]) - end) + minetest.after(0.15, function(name) + if particlespawners[name] then + minetest.delete_particlespawner(particlespawners[name]) + end + end, name) end if minetest.get_item_group(minetest.get_node(player_pos).name, "water") > 0 then diff --git a/mods/hunger/init.lua b/mods/hunger/init.lua index 19151a6..3e11eec 100644 --- a/mods/hunger/init.lua +++ b/mods/hunger/init.lua @@ -219,9 +219,11 @@ local function on_item_eat(hpdata, replace_with_item, itemstack, texture = "magicpuff.png" }) - minetest.after(0.15, function() - minetest.delete_particlespawner(particlespawners[name]) - end) + minetest.after(0.15, function(name) + if particlespawner[name] then + minetest.delete_particlespawner(particlespawners[name]) + end + end, name) player_effects.apply_effect(player, "hunger_eating") diff --git a/mods/item_drop/init.lua b/mods/item_drop/init.lua index a8a1e77..fb290ac 100644 --- a/mods/item_drop/init.lua +++ b/mods/item_drop/init.lua @@ -138,8 +138,10 @@ function minetest.handle_node_drops(pos, drops, digger) -- FIXME this doesnt work for deactiveted objects if minetest.settings:get("remove_items") and tonumber(minetest.settings:get("remove_items")) then minetest.after(tonumber(minetest.settings:get("remove_items")), function(obj) - obj:remove() - end, obj) + if obj then + obj:remove() + end + end, obj) end end end diff --git a/mods/player_skins/init.lua b/mods/player_skins/init.lua index 122bcac..c329f01 100644 --- a/mods/player_skins/init.lua +++ b/mods/player_skins/init.lua @@ -125,7 +125,7 @@ local function on_globalstep(dtime) end end -minetest.after(0, on_load) +minetest.register_on_mods_loaded(on_load) minetest.register_on_shutdown(on_shutdown) diff --git a/mods/tnt/init.lua b/mods/tnt/init.lua index 739ae93..6e0dd85 100644 --- a/mods/tnt/init.lua +++ b/mods/tnt/init.lua @@ -231,7 +231,7 @@ local function on_load() end end -minetest.after(0, on_load) +minetest.register_on_mods_loaded(on_load) -- Nodes diff --git a/mods/village/generate.lua b/mods/village/generate.lua index 0668b24..dadf81c 100644 --- a/mods/village/generate.lua +++ b/mods/village/generate.lua @@ -455,8 +455,4 @@ function village.spawn_village(pos, pr) end end -minetest.after( - 0, - function() - village.load_villages() -end) +minetest.register_on_mods_loaded(village.load_villages) diff --git a/mods/village/mapgen.lua b/mods/village/mapgen.lua index cdc2da6..3597e2f 100644 --- a/mods/village/mapgen.lua +++ b/mods/village/mapgen.lua @@ -98,9 +98,9 @@ minetest.register_lbm( minetest.after( 2.0, - function() + function(pos, pr) village.spawn_village(pos, pr) - end) + end, pos, pr) else minetest.log("action", "[village] Cannot spawn village, too near the static spawnpoint") end