From 4fb0956d56ab50241b39e140665150dba9414398 Mon Sep 17 00:00:00 2001 From: Gabriel PĂ©rez-Cerezo Date: Sun, 21 Oct 2018 16:21:51 +0200 Subject: 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. --- advtrains/atc.lua | 3 +++ advtrains/path.lua | 2 +- advtrains/trainlogic.lua | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) (limited to 'advtrains') 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 -- cgit v1.2.3