From 5ba1c48589e855ab3143242de0eafe2890589969 Mon Sep 17 00:00:00 2001 From: orwell Date: Wed, 29 Jan 2025 22:17:31 +0100 Subject: Try to narrow down heisenbug with endless loop --- advtrains/occupation.lua | 2 ++ advtrains/path.lua | 7 +++++-- advtrains_interlocking/train_sections.lua | 6 +++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/advtrains/occupation.lua b/advtrains/occupation.lua index 20a986e..66ad36c 100644 --- a/advtrains/occupation.lua +++ b/advtrains/occupation.lua @@ -103,7 +103,9 @@ function o.clear_all_items(train_id, pos) local t = occget(pos) if not t then return end local i = 1 + local _cnt = 0 while t[i] do + _cnt = _cnt + 1; if _cnt > 10000 then error("Loop trap in advtrains.occ,clear_all_items was triggered!") end if t[i]==train_id then table.remove(t, i) table.remove(t, i) diff --git a/advtrains/path.lua b/advtrains/path.lua index 4807361..84d295d 100644 --- a/advtrains/path.lua +++ b/advtrains/path.lua @@ -112,14 +112,17 @@ end -- before returning from the calling function. function advtrains.path_invalidate(train, ignore_lock) if advtrains.lock_path_inval and not ignore_lock then - atwarn("Train ",train.train_id,": Illegal path invalidation has occured during train step:") + atwarn("Train ",train.id,": Illegal path invalidation has occured during train step:") atwarn(debug.traceback()) end - if train.path then + --atdebug("path_invalidate for",train.id) + local _cnt = 0 for i,p in pairs(train.path) do + _cnt = _cnt + 1; if _cnt > 10000 then error("Loop trap in advtrains.path_invalidate was triggered!") end advtrains.occ.clear_all_items(train.id, advtrains.round_vector_floor_y(p)) end + --atdebug("occ cleared") end train.path = nil train.path_dist = nil diff --git a/advtrains_interlocking/train_sections.lua b/advtrains_interlocking/train_sections.lua index 0420463..a1ee87f 100644 --- a/advtrains_interlocking/train_sections.lua +++ b/advtrains_interlocking/train_sections.lua @@ -157,13 +157,13 @@ advtrains.tnc_register_on_enter(function(pos, id, train, index) if tcb and train.path_cp[index] and train.path_cn[index] then -- forward conn local connid = train.path_cn[index] - local ts = tcb[connid].ts_id and ildb.get_ts(tcb[connid].ts_id) + local ts = tcb[connid] and tcb[connid].ts_id and ildb.get_ts(tcb[connid].ts_id) if ts then setsection(id, train, tcb[connid].ts_id, ts, {p=pos, s=connid}) end -- backward conn (safety only) connid = train.path_cp[index] - ts = tcb[connid].ts_id and ildb.get_ts(tcb[connid].ts_id) + ts = tcb[connid] and tcb[connid].ts_id and ildb.get_ts(tcb[connid].ts_id) if ts then setsection(id, train, tcb[connid].ts_id, ts, {p=pos, s=connid}, true) end @@ -177,7 +177,7 @@ advtrains.tnc_register_on_leave(function(pos, id, train, index) if tcb and train.path_cp[index] then -- backward conn local connid = train.path_cp[index] - local ts = tcb[connid].ts_id and ildb.get_ts(tcb[connid].ts_id) + local ts = tcb[connid] and tcb[connid].ts_id and ildb.get_ts(tcb[connid].ts_id) if ts then freesection(id, train, tcb[connid].ts_id, ts) end -- cgit v1.2.3