From 0dee7792f4614a776e25385d7ffcc1070ada7e1f Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Sun, 12 Mar 2023 23:41:19 +0000 Subject: [PATCH 1/5] Log where map unloaded before light damage code. #3430 debugging --- mods/ENTITIES/mcl_mobs/physics.lua | 36 +++++++++++++++++------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/physics.lua b/mods/ENTITIES/mcl_mobs/physics.lua index 1b6d7c544..73ed94758 100644 --- a/mods/ENTITIES/mcl_mobs/physics.lua +++ b/mods/ENTITIES/mcl_mobs/physics.lua @@ -622,23 +622,29 @@ function mob_class:do_env_damage() return true end - local sunlight = minetest.get_natural_light(pos, self.time_of_day) + local node = minetest.get_node(pos) + if node then + if node.name ~= "ignore" then + local sunlight = minetest.get_natural_light(pos, self.time_of_day) - -- bright light harms mob - if self.light_damage ~= 0 and (sunlight or 0) > 12 then - if self:deal_light_damage(pos, self.light_damage) then - return true - end - end - local _, dim = mcl_worlds.y_to_layer(pos.y) - if (self.sunlight_damage ~= 0 or self.ignited_by_sunlight) and (sunlight or 0) >= minetest.LIGHT_MAX and dim == "overworld" then - if self.armor_list and not self.armor_list.helmet or not self.armor_list or self.armor_list and self.armor_list.helmet and self.armor_list.helmet == "" then - if self.ignited_by_sunlight then - mcl_burning.set_on_fire(self.object, 10) - else - self:deal_light_damage(pos, self.sunlight_damage) - return true + if self.light_damage ~= 0 and (sunlight or 0) > 12 then + if self:deal_light_damage(pos, self.light_damage) then + return true + end end + local _, dim = mcl_worlds.y_to_layer(pos.y) + if (self.sunlight_damage ~= 0 or self.ignited_by_sunlight) and (sunlight or 0) >= minetest.LIGHT_MAX and dim == "overworld" then + if self.armor_list and not self.armor_list.helmet or not self.armor_list or self.armor_list and self.armor_list.helmet and self.armor_list.helmet == "" then + if self.ignited_by_sunlight then + mcl_burning.set_on_fire(self.object, 10) + else + self:deal_light_damage(pos, self.sunlight_damage) + return true + end + end + end + else + minetest.log("warning", "Pos is ignored: " .. dump(pos)) end end From ae7cfdff698a73fcaeca6749515434dfa3f3fa3f Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Sun, 12 Mar 2023 23:45:41 +0000 Subject: [PATCH 2/5] Ensure conditional doesn't mask bug crash issue --- mods/ENTITIES/mcl_mobs/physics.lua | 40 ++++++++++++++++-------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/physics.lua b/mods/ENTITIES/mcl_mobs/physics.lua index 73ed94758..b6149d2a9 100644 --- a/mods/ENTITIES/mcl_mobs/physics.lua +++ b/mods/ENTITIES/mcl_mobs/physics.lua @@ -625,27 +625,31 @@ function mob_class:do_env_damage() local node = minetest.get_node(pos) if node then if node.name ~= "ignore" then - local sunlight = minetest.get_natural_light(pos, self.time_of_day) - - if self.light_damage ~= 0 and (sunlight or 0) > 12 then - if self:deal_light_damage(pos, self.light_damage) then - return true - end - end - local _, dim = mcl_worlds.y_to_layer(pos.y) - if (self.sunlight_damage ~= 0 or self.ignited_by_sunlight) and (sunlight or 0) >= minetest.LIGHT_MAX and dim == "overworld" then - if self.armor_list and not self.armor_list.helmet or not self.armor_list or self.armor_list and self.armor_list.helmet and self.armor_list.helmet == "" then - if self.ignited_by_sunlight then - mcl_burning.set_on_fire(self.object, 10) - else - self:deal_light_damage(pos, self.sunlight_damage) - return true - end - end - end + -- put below code in this block if we can prove that unloaded maps are causing crash. + -- it should warn then error else minetest.log("warning", "Pos is ignored: " .. dump(pos)) end + + local sunlight = minetest.get_natural_light(pos, self.time_of_day) + + if self.light_damage ~= 0 and (sunlight or 0) > 12 then + if self:deal_light_damage(pos, self.light_damage) then + return true + end + end + local _, dim = mcl_worlds.y_to_layer(pos.y) + if (self.sunlight_damage ~= 0 or self.ignited_by_sunlight) and (sunlight or 0) >= minetest.LIGHT_MAX and dim == "overworld" then + if self.armor_list and not self.armor_list.helmet or not self.armor_list or self.armor_list and self.armor_list.helmet and self.armor_list.helmet == "" then + if self.ignited_by_sunlight then + mcl_burning.set_on_fire(self.object, 10) + else + self:deal_light_damage(pos, self.sunlight_damage) + return true + end + end + end + end local y_level = self.collisionbox[2] From 97091de67f2f346ac73502de0b627bac3bd121d4 Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Mon, 13 Mar 2023 01:51:09 +0000 Subject: [PATCH 3/5] Log pos info only prior to crash --- mods/ENTITIES/mcl_mobs/api.lua | 4 ++++ mods/ENTITIES/mcl_mobs/physics.lua | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index dd8c7cb5e..355f40413 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -510,6 +510,10 @@ function mob_class:on_step(dtime) else warn_user_error () local pos = self.object:get_pos() + local node = minetest.get_node(pos) + if node and node.name == "ignore" then + minetest.log("warning", "Pos is ignored: " .. dump(pos)) + end log_error (dump(retVal), dump(pos), dump(self)) end else diff --git a/mods/ENTITIES/mcl_mobs/physics.lua b/mods/ENTITIES/mcl_mobs/physics.lua index b6149d2a9..673c08c8a 100644 --- a/mods/ENTITIES/mcl_mobs/physics.lua +++ b/mods/ENTITIES/mcl_mobs/physics.lua @@ -628,7 +628,7 @@ function mob_class:do_env_damage() -- put below code in this block if we can prove that unloaded maps are causing crash. -- it should warn then error else - minetest.log("warning", "Pos is ignored: " .. dump(pos)) + --minetest.log("warning", "Pos is ignored: " .. dump(pos)) end local sunlight = minetest.get_natural_light(pos, self.time_of_day) From be269b2034972479482d00aa0df4475a2f033b59 Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Tue, 14 Mar 2023 15:19:39 +0000 Subject: [PATCH 4/5] Make error handling safe in case pos is missing --- mods/ENTITIES/mcl_mobs/api.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 355f40413..455ca47d9 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -510,9 +510,11 @@ function mob_class:on_step(dtime) else warn_user_error () local pos = self.object:get_pos() - local node = minetest.get_node(pos) - if node and node.name == "ignore" then - minetest.log("warning", "Pos is ignored: " .. dump(pos)) + if pos then + local node = minetest.get_node(pos) + if node and node.name == "ignore" then + minetest.log("warning", "Pos is ignored: " .. dump(pos)) + end end log_error (dump(retVal), dump(pos), dump(self)) end From ff1b941d193c4db2f61450dfa4b8bfa704b0d609 Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Tue, 14 Mar 2023 15:26:17 +0000 Subject: [PATCH 5/5] Clean and improve profiler info --- mods/ENTITIES/mcl_mobs/api.lua | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 455ca47d9..50b9ad8ec 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -5,25 +5,18 @@ local math, vector, minetest, mcl_mobs = math, vector, minetest, mcl_mobs local PATHFINDING = "gowp" local CRASH_WARN_FREQUENCY = 60 +local LIFETIMER_DISTANCE = 47 -- Localize local S = minetest.get_translator("mcl_mobs") local DEVELOPMENT = minetest.settings:get_bool("mcl_development",false) -local LOGGING_ON = minetest.settings:get_bool("mcl_logging_mobs_villager",false) -local function mcl_log (message) - if LOGGING_ON then - mcl_util.mcl_log (message, "[Mobs]", true) - end -end - -- Invisibility mod check mcl_mobs.invis = {} local remove_far = true -local mobs_griefing = minetest.settings:get_bool("mobs_griefing") ~= false -local spawn_protected = minetest.settings:get_bool("mobs_spawn_protected") ~= false + local mobs_debug = minetest.settings:get_bool("mobs_debug", false) -- Shows helpful debug info above each mob local spawn_logging = minetest.settings:get_bool("mcl_logging_mobs_spawn",true) @@ -503,6 +496,7 @@ end -- main mob function function mob_class:on_step(dtime) if not DEVELOPMENT then + -- Removed as bundled Lua (5.1 doesn't support xpcall) --local status, retVal = xpcall(on_step_work, on_step_error_handler, self, dtime) local status, retVal = pcall(on_step_work, self, dtime) if status then @@ -524,12 +518,13 @@ function mob_class:on_step(dtime) end local timer = 0 -minetest.register_globalstep(function(dtime) + +local function update_lifetimer(dtime) timer = timer + dtime if timer < 1 then return end for _, player in pairs(minetest.get_connected_players()) do local pos = player:get_pos() - for _, obj in pairs(minetest.get_objects_inside_radius(pos, 47)) do + for _, obj in pairs(minetest.get_objects_inside_radius(pos, LIFETIMER_DISTANCE)) do local lua = obj:get_luaentity() if lua and lua.is_mob then lua.lifetimer = math.max(20, lua.lifetimer) @@ -538,6 +533,10 @@ minetest.register_globalstep(function(dtime) end end timer = 0 +end + +minetest.register_globalstep(function(dtime) + update_lifetimer(dtime) end)