Merge pull request 'Mob Step error handling' (#3452) from mobs_error_handling into master

Reviewed-on: https://git.minetest.land/MineClone2/MineClone2/pulls/3452
This commit is contained in:
ancientmarinerdev 2023-02-16 23:34:07 +00:00
commit b2e0b9b08b
1 changed files with 32 additions and 2 deletions

View File

@ -4,6 +4,7 @@ local math, vector, minetest, mcl_mobs = math, vector, minetest, mcl_mobs
-- API for Mobs Redo: MineClone 2 Edition (MRM)
local PATHFINDING = "gowp"
local CRASH_WARN_FREQUENCY = 60
-- Localize
local S = minetest.get_translator("mcl_mobs")
@ -357,8 +358,7 @@ function mob_class:outside_limits()
end
end
-- main mob function
function mob_class:on_step(dtime)
local function on_step_work (self, dtime)
local pos = self.object:get_pos()
if not pos then return end
@ -446,6 +446,36 @@ function mob_class:on_step(dtime)
end
end
local last_crash_warn_time = 0
local on_step_error_handler = function ()
local info = debug.getinfo(1, "SnlufL")
local current_time = os.time()
local time_since_warning = current_time - last_crash_warn_time
--minetest.log("previous_crash_time: " .. current_time)
--minetest.log("last_crash_time: " .. last_crash_warn_time)
--minetest.log("time_since_warning: " .. time_since_warning)
if time_since_warning > CRASH_WARN_FREQUENCY then
last_crash_warn_time = current_time
minetest.log("A game crashing bug was prevented. Please provide debug.log information to MineClone2 dev team for investigation. (Search for: --- Bug report start)")
end
minetest.log("action", "--- Bug report start (please provide a few lines before this also for context) ---")
minetest.log("action", "Stack trace: ".. tostring(debug.traceback()))
minetest.log("action", "Bug info: ".. dump(info))
minetest.log("action", "--- Bug report end ---")
end
-- main mob function
function mob_class:on_step(dtime)
local status, retVal = xpcall(on_step_work, on_step_error_handler, self, dtime)
if status then
return retVal
end
end
local timer = 0
minetest.register_globalstep(function(dtime)
timer = timer + dtime