Fix scheduler crash (H#133)

for loops don't work with manipulating i
This commit is contained in:
orwell96 2019-11-21 14:59:39 +01:00
parent 8c55442076
commit 576365627a
2 changed files with 7 additions and 5 deletions

View File

@ -90,7 +90,7 @@ function sched.enqueue(rwtime, handler, evtdata, unitid, unitlim)
ucn = (units_cnt[unitid] or 0)
local ulim=(unitlim or UNITS_THRESH)
if ucn >= ulim then
atwarn("[lines][scheduler] discarding enqueue for",handler,"(limit",ulim,") because unit",unitid,"has already",ucn,"schedules enqueued")
atlog("[lines][scheduler] discarding enqueue for",handler,"(limit",ulim,") because unit",unitid,"has already",ucn,"schedules enqueued")
return false
end
@ -118,10 +118,12 @@ end
-- Discards all schedules for unit "unitid" (removes them from the queue)
function sched.discard_all(unitid)
for i=1,#queue do
local i = 1
while i<=#queue do
if queue[i].u == unitid then
table.remove(queue,i)
i=i-1
else
i=i+1
end
end
units_cnt[unitid] = 0

View File

@ -131,10 +131,10 @@ function ac.run_in_env(pos, evtdata, customfct_p)
-- add lines scheduler if enabled
if advtrains.lines and advtrains.lines.sched then
customfct.schedule = function(rwtime, msg)
advtrains.lines.sched.enqueue(rwtime, "atlatc_env", {pos=pos, msg=msg}, advtrains.encode_pos(pos), 1)
return advtrains.lines.sched.enqueue(rwtime, "atlatc_env", {pos=pos, msg=msg}, advtrains.encode_pos(pos), 1)
end
customfct.schedule_in = function(rwtime, msg)
advtrains.lines.sched.enqueue_in(rwtime, "atlatc_env", {pos=pos, msg=msg}, advtrains.encode_pos(pos), 1)
return advtrains.lines.sched.enqueue_in(rwtime, "atlatc_env", {pos=pos, msg=msg}, advtrains.encode_pos(pos), 1)
end
end