ecs-lua icon indicating copy to clipboard operation
ecs-lua copied to clipboard

bug: SystemExecutor:ExecTasks, scheduler is nil in while loop

Open kakagamescom opened this issue 3 years ago • 0 comments

When i run task system according to the document. i got scheduler is nil error.

local log = {}
local Task_A = ECS.System('task', function()
   -- In this example, TASK_A takes time to execute, delaying its execution
   local i = 0
   while i <= 4000 do
      i = i + 1
      if i%1000 == 0 then
         coroutine.yield()
      end
   end
   
   table.insert(log, 'A')
end)

local Task_B = ECS.System('task', function()
   table.insert(log, 'B')
end)

local Task_C = ECS.System('task', function()
   table.insert(log, 'C')
end)

local Task_D = ECS.System('task', function()
   table.insert(log, 'D')
end)

local Task_E = ECS.System('task', function()
   table.insert(log, 'E')
end)

local Task_F = ECS.System('task', function()
   table.insert(log, 'F')
end)

local Task_G = ECS.System('task', function()
   table.insert(log, 'G')
end)

local Task_H = ECS.System('task', function(self)
   table.insert(log, 'H')
end)

--[[         
   A<-------C<---+-----F<----+
            |    |     |     |
       +----+    E<----+     H
       |         |           |
   B<--+----D<---+------G<---+

   A - has no dependency
   B - has no dependency
   C - Depends on A,B
   D - Depends on B
   E - Depends on A,B,C,D
   F - Depends on A,B,C,D,E
   G - Depends on B,D
   H - Depends on A,B,C,D,E,F,G

   Completion order will be B,D,G,A,C,E,F,H      

   > In this example, TASK_A takes time to execute, delaying its execution
]]
Task_A.Before = {Task_C}
Task_B.Before = {Task_D}
Task_C.After = {Task_B}
Task_D.Before = {Task_G}
Task_F.After = {Task_E}
Task_E.After = {Task_D, Task_C}
Task_C.Before = {Task_F}
Task_H.After = {Task_F, Task_G}

world:AddSystem(Task_A)
world:AddSystem(Task_B)
world:AddSystem(Task_C)
world:AddSystem(Task_D)
world:AddSystem(Task_E)
world:AddSystem(Task_F)
world:AddSystem(Task_G)
world:AddSystem(Task_H)

kakagamescom avatar Oct 18 '22 03:10 kakagamescom