aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Pérez-Cerezo <gabriel@gpcf.eu>2018-10-21 16:21:51 +0200
committerGabriel Pérez-Cerezo <gabriel@gpcf.eu>2018-10-21 16:21:51 +0200
commit4fb0956d56ab50241b39e140665150dba9414398 (patch)
treebb245e86b15d2a015c84a4f1542d52c75a5f57d1
parentd15210603f4654d20bc15be449cdc672dc4d53c5 (diff)
downloadadvtrains-4fb0956d56ab50241b39e140665150dba9414398.tar.gz
advtrains-4fb0956d56ab50241b39e140665150dba9414398.tar.bz2
advtrains-4fb0956d56ab50241b39e140665150dba9414398.zip
Various sanity checks against nil
These checks have been accumulated over time on linuxworks. They seem to be necessary, minetest kept crashing when they were removed.
-rw-r--r--advtrains/atc.lua3
-rw-r--r--advtrains/path.lua2
-rw-r--r--advtrains/trainlogic.lua3
3 files changed, 7 insertions, 1 deletions
diff --git a/advtrains/atc.lua b/advtrains/atc.lua
index 465a0ec..00cfde1 100644
--- a/advtrains/atc.lua
+++ b/advtrains/atc.lua
@@ -32,6 +32,9 @@ function atc.send_command(pos, par_tid)
atc.train_reset_command(train_id)
local arrowconn=atc.controllers[pts].arrowconn
local train=advtrains.trains[train_id]
+ if train.path == nil then
+ return
+ end
for index, ppos in pairs(train.path) do
if vector.equals(advtrains.round_vector_floor_y(ppos), pos) then
advtrains.trains[train_id].atc_arrow =
diff --git a/advtrains/path.lua b/advtrains/path.lua
index 506f27f..4955854 100644
--- a/advtrains/path.lua
+++ b/advtrains/path.lua
@@ -18,7 +18,7 @@ function advtrains.conway(midreal, prev, drives_on)--in order prev,mid,return
local nconnid = advtrains.get_matching_conn(pconnid, #midconns)
local next, next_connid, _, nextrailheight = advtrains.get_adjacent_rail(mid, midconns, nconnid, drives_on)
- if not next then
+ if not next or not midconns or not midconns[nconnid] then
return nil
end
return vector.add(advtrains.round_vector_floor_y(next), {x=0, y=nextrailheight, z=0}), midconns[nconnid].c
diff --git a/advtrains/trainlogic.lua b/advtrains/trainlogic.lua
index c3fbe4a..6ab2b0d 100644
--- a/advtrains/trainlogic.lua
+++ b/advtrains/trainlogic.lua
@@ -540,6 +540,9 @@ function advtrains.train_step_b(id, train, dtime)
local collpos
local coll_grace=1
+ if train.end_index == nil then
+ return
+ end
if train.movedir==1 then
collpos=advtrains.get_real_index_position(train.path, train.index-coll_grace)
else