diff options
author | orwell96 <mono96.mml@gmail.com> | 2017-05-15 13:37:06 +0200 |
---|---|---|
committer | orwell96 <mono96.mml@gmail.com> | 2017-05-30 09:20:01 +0200 |
commit | e484654f896a40910cdeefdc2ac64ea8e9556c89 (patch) | |
tree | 3871961349b93a2dfae4781a2f5c907370553b3b | |
parent | 74c8784b21c635ae310773e7105d22e3928a049a (diff) | |
download | advtrains-e484654f896a40910cdeefdc2ac64ea8e9556c89.tar.gz advtrains-e484654f896a40910cdeefdc2ac64ea8e9556c89.tar.bz2 advtrains-e484654f896a40910cdeefdc2ac64ea8e9556c89.zip |
Re-add debug ring buffer and print its contents on a lua crash
When the crash on linuxworks has been fixed, the ringbuffer will go into master and behind an option
also fix last commit
-rw-r--r-- | advtrains/advtrains/debugringbuffer.lua | 44 | ||||
-rw-r--r-- | advtrains/advtrains/helpers.lua | 13 | ||||
-rw-r--r-- | advtrains/advtrains/init.lua | 19 | ||||
-rw-r--r-- | advtrains/advtrains/nodedb.lua | 6 | ||||
-rw-r--r-- | advtrains/advtrains/trainlogic.lua | 8 | ||||
-rw-r--r-- | advtrains/advtrains/wagons.lua | 2 |
6 files changed, 89 insertions, 3 deletions
diff --git a/advtrains/advtrains/debugringbuffer.lua b/advtrains/advtrains/debugringbuffer.lua new file mode 100644 index 0000000..1be9da9 --- /dev/null +++ b/advtrains/advtrains/debugringbuffer.lua @@ -0,0 +1,44 @@ +--so, some ringbuffers one for each train + +local ringbuflen=1000 + +local ringbufs={} +local ringbufcnt={} + +function advtrains.drb_record(tid, msg) + if not ringbufs[tid] then + ringbufs[tid]={} + ringbufcnt[tid]=0 + end + ringbufs[tid][ringbufcnt[tid]]=msg + ringbufcnt[tid]=ringbufcnt[tid]+1 + if ringbufcnt[tid] > ringbuflen then + ringbufcnt[tid]=0 + end +end +function advtrains.drb_dump(tid) + atlog("Debug ring buffer output for '"..tid.."':") + local stopcnt=ringbufcnt[tid] + if not stopcnt then + atlog("ID unknown!") + return + end + repeat + atlog(ringbufs[tid][ringbufcnt[tid]]) + ringbufcnt[tid]=ringbufcnt[tid]+1 + if ringbufcnt[tid] > ringbuflen then + ringbufcnt[tid]=0 + end + until ringbufcnt[tid]==stopcnt +end + +minetest.register_chatcommand("atdebug_show", + { + params = "train sid", -- Short parameter description + description = "Dump debug log", -- Full description + privs = {train_operator=true}, -- Require the "privs" privilege to run + func = function(name, param) + advtrains.drb_dump(param) + end, -- Called when command is run. + -- Returns boolean success and text output. + }) diff --git a/advtrains/advtrains/helpers.lua b/advtrains/advtrains/helpers.lua index 039b4f0..df2d9a8 100644 --- a/advtrains/advtrains/helpers.lua +++ b/advtrains/advtrains/helpers.lua @@ -170,6 +170,19 @@ function advtrains.minAngleDiffRad(r1, r2) return try3
end
end
+ +function advtrains.dumppath(path)
+ atlog("Dumping a path:")
+ if not path then atlog("dumppath: no path(nil)") return end
+ local temp_path={}
+ for ipt, iit in pairs(path) do
+ temp_path[#temp_path+1]={i=ipt, p=iit}
+ end
+ table.sort(temp_path, function (k1, k2) return k1.i < k2.i end)
+ for _,pit in ipairs(temp_path) do
+ atlog(pit.i.." > "..minetest.pos_to_string(pit.p))
+ end
+end
function advtrains.merge_tables(a, ...)
local new={}
diff --git a/advtrains/advtrains/init.lua b/advtrains/advtrains/init.lua index c0d581d..26dbd8c 100644 --- a/advtrains/advtrains/init.lua +++ b/advtrains/advtrains/init.lua @@ -15,6 +15,13 @@ function advtrains.pcall(fun) if no_action then return end local succ, return1, return2, return3, return4=xpcall(fun, function(err) + if advtrains.atprint_context_tid then + local train=advtrains.trains[advtrains.atprint_context_tid_full] + advtrains.dumppath(train.path) + atwarn("Dumping last debug outputs: ", err) + atprint("Train state: index",train.index,"end_index", train.end_index,"| max_iot", train.max_index_on_track, "min_iot", train.min_index_on_track, "<> pe_min", train.path_extent_min,"pe_max", train.path_extent_max) + advtrains.drb_dump(advtrains.atprint_context_tid) + end atwarn("Lua Error occured: ", err) atwarn(debug.traceback()) end) @@ -72,7 +79,12 @@ function advtrains.print_concat_table(a) return str end -atprint=function() end +atprint=function(t, ...) + local context=advtrains.atprint_context_tid + if not context then return end + local text=advtrains.print_concat_table({t, ...}) + advtrains.drb_record(context, text) +end atlog=function(t, ...) local context=advtrains.atprint_context_tid if not context then return end @@ -104,6 +116,8 @@ advtrains.meseconrules = {x=0, y=-1, z=-1}, {x=0, y=-2, z=0}} + +dofile(advtrains.modpath.."/debugringbuffer.lua") dofile(advtrains.modpath.."/trainlogic.lua") dofile(advtrains.modpath.."/trainhud.lua") @@ -260,9 +274,12 @@ end local init_load=false local save_interval=20 local save_timer=save_interval +advtrains.mainloop_runcnt=0 minetest.register_globalstep(function(dtime_mt) return advtrains.pcall(function() + advtrains.mainloop_runcnt=advtrains.mainloop_runcnt+1 + atprint("Running the main loop, runcnt",advtrains.mainloop_runcnt) --call load once. see advtrains.load() comment if not init_load then advtrains.load() diff --git a/advtrains/advtrains/nodedb.lua b/advtrains/advtrains/nodedb.lua index 7ebf755..4dc451a 100644 --- a/advtrains/advtrains/nodedb.lua +++ b/advtrains/advtrains/nodedb.lua @@ -286,7 +286,7 @@ local ptime=0 minetest.register_chatcommand("at_restore_ndb", { params = "", -- Short parameter description - description = "Write node db back to map", -- Full description + description = "Write node db back to map and find ghost nodes", -- Full description privs = {train_operator=true, worldedit=true}, -- Require the "privs" privilege to run func = function(name, param) return advtrains.pcall(function() @@ -298,5 +298,9 @@ minetest.register_chatcommand("at_restore_ndb", return true end) end, + privs = {train_operator=true}, -- Require the "privs" privilege to run + func = function(name, param) + ndb.restore_all() + end, -- Called when command is run. }) diff --git a/advtrains/advtrains/trainlogic.lua b/advtrains/advtrains/trainlogic.lua index f307026..c4df656 100644 --- a/advtrains/advtrains/trainlogic.lua +++ b/advtrains/advtrains/trainlogic.lua @@ -56,14 +56,17 @@ advtrains.mainloop_trainlogic=function(dtime) advtrains.detector.on_node={} for k,v in pairs(advtrains.trains) do advtrains.atprint_context_tid=sid(k) + advtrains.atprint_context_tid_full=k advtrains.train_step_a(k, v, dtime) end for k,v in pairs(advtrains.trains) do advtrains.atprint_context_tid=sid(k) + advtrains.atprint_context_tid_full=k advtrains.train_step_b(k, v, dtime) end advtrains.atprint_context_tid=nil + advtrains.atprint_context_tid_full=nil atprintbm("trainsteps", t) endstep() @@ -131,6 +134,10 @@ train step structure: ]] function advtrains.train_step_a(id, train, dtime) + atprint("--- runcnt ",advtrains.mainloop_runcnt,": index",train.index,"end_index", train.end_index,"| max_iot", train.max_index_on_track, "min_iot", train.min_index_on_track, "<> pe_min", train.path_extent_min,"pe_max", train.path_extent_max) + if train.min_index_on_track then + assert(math.floor(train.min_index_on_track)==train.min_index_on_track) + end --- 1. LEGACY STUFF --- if not train.drives_on or not train.max_speed then advtrains.update_trainpart_properties(id) @@ -235,6 +242,7 @@ function advtrains.train_step_a(id, train, dtime) local t_info, train_pos=sid(id), train.path[math.floor(train.index)] if train_pos then t_info=t_info.." @"..minetest.pos_to_string(train_pos) + --atprint("train_pos:",train_pos) end --apply off-track handling: diff --git a/advtrains/advtrains/wagons.lua b/advtrains/advtrains/wagons.lua index 3325879..3eabd2f 100644 --- a/advtrains/advtrains/wagons.lua +++ b/advtrains/advtrains/wagons.lua @@ -286,7 +286,7 @@ function wagon:on_step(dtime) --check infotext
local outside=self:train().text_outside or ""
if self.object:get_properties().infotext~=outside then
- self.object:set_properties({infotext=outside})
+ self.object:set_properties({infotext=sid(self.train_id)})
end
local gp=self:train()
|