Fix crash when tasks are scheduled for the next timestep into priority 2 from inside a function dispatched from priority 2

This commit is contained in:
teknomunk 2024-11-29 11:44:19 -06:00
parent 528531e37b
commit 06b8fa561e
2 changed files with 12 additions and 1 deletions

@ -132,6 +132,7 @@ local function globalstep(dtime)
-- Run tasks that must be run this timestep (now-main)
every_globalstep(dtime)
local next_main_task = run_queue[2]
run_queue[2] = nil
while next_main_task do
local task = next_main_task
next_main_task = task.next
@ -139,7 +140,6 @@ local function globalstep(dtime)
task:func(dtime)
free_task(task)
end
run_queue[2] = nil
-- Launch asynchronous tasks that may be issued any time (background-async)
local next_background_async_task = run_queue[3]

@ -190,5 +190,16 @@ describe('vl_scheduler',function()
call_globalstep(0.05)
end
end)
it('can schedule new tasks recursively and they run on the next timestep',function()
local vl_scheduler = _G.vl_scheduler
vl_scheduler.after(0, 2, function() end)
vl_scheduler.after(0, 2, function()
vl_scheduler.after(0, 2, function() end)
vl_scheduler.after(0, 2, function() end)
end)
assert.no_error(function()
call_globalstep(0.05)
end)
end)
end)