summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcheapie <no-email-for-you@example.com>2024-08-06 12:44:29 -0500
committercheapie <no-email-for-you@example.com>2024-08-06 12:44:29 -0500
commitfe4c23ecd06771298e7227462acc0d209f6fbf5f (patch)
treec73f02dcf31c1fec69033e234c780e421561eb54
parentafc8b657a986456627e84734b703a2c3c2e307e2 (diff)
downloadcelevator-fe4c23ecd06771298e7227462acc0d209f6fbf5f.tar
celevator-fe4c23ecd06771298e7227462acc0d209f6fbf5f.tar.gz
celevator-fe4c23ecd06771298e7227462acc0d209f6fbf5f.tar.bz2
celevator-fe4c23ecd06771298e7227462acc0d209f6fbf5f.tar.xz
celevator-fe4c23ecd06771298e7227462acc0d209f6fbf5f.zip
Fix possible crashes when removing a dispatcher connection that isn't idle
-rw-r--r--dispatcherfw.lua19
1 files changed, 13 insertions, 6 deletions
diff --git a/dispatcherfw.lua b/dispatcherfw.lua
index 741175c..428312c 100644
--- a/dispatcherfw.lua
+++ b/dispatcherfw.lua
@@ -14,6 +14,7 @@ if not mem.dbdcalls then mem.dbdcalls = {} end
local function getpos(carid)
if not mem.params.floorsserved[carid] then return 0 end
+ if not mem.carstatus[carid] then return 0 end
local floormap = {}
local floorheights = {}
for i=1,#mem.params.floornames,1 do
@@ -34,6 +35,7 @@ local function getpos(carid)
end
local function getdpos(carid)
+ if not mem.carstatus[carid] then return 0 end
local floormap = {}
local floorheights = {}
for i=1,#mem.params.floornames,1 do
@@ -272,6 +274,7 @@ local function buildstopsequence(carid,startfloor,direction,target,targetdir,lea
end
local function calculateeta(carid,floor,direction)
+ if not mem.carstatus[carid] then return 999 end
local leaving = (getpos(carid) ~= getdpos(carid)) and (getpos(carid) == floor)
local sequence = buildstopsequence(carid,getpos(carid),mem.carstatus[carid].direction,floor,direction,leaving)
local doorstate = mem.carstatus[carid].doorstate
@@ -764,13 +767,17 @@ elseif event.type == "abm" or event.type == "remotewake" or (event.iid == "run"
end
for k,call in ipairs(mem.dbdcalls) do
if call.assigned then
- local carstate = mem.carstatus[call.assigned].state
- local doorstate = mem.carstatus[call.assigned].doorstate
- local direction = mem.carstatus[call.assigned].direction
- local desireddir = (call.srcfloor < call.destfloor and "up" or "down")
- if direction == desireddir and doorstate ~= "closed" then
- if carstate == "normal" then send(call.assigned,"carcall",realtocarfloor(call.assigned,call.destfloor)) end
+ if not mem.carstatus[call.assigned] then
table.remove(mem.dbdcalls,k)
+ else
+ local carstate = mem.carstatus[call.assigned].state
+ local doorstate = mem.carstatus[call.assigned].doorstate
+ local direction = mem.carstatus[call.assigned].direction
+ local desireddir = (call.srcfloor < call.destfloor and "up" or "down")
+ if direction == desireddir and doorstate ~= "closed" then
+ if carstate == "normal" then send(call.assigned,"carcall",realtocarfloor(call.assigned,call.destfloor)) end
+ table.remove(mem.dbdcalls,k)
+ end
end
else
local direction = (call.srcfloor < call.destfloor and "up" or "down")