From 3a1c59057276f02e0b9be774d2f8e7d35ff92941 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Sun, 24 Mar 2013 18:55:05 +0000 Subject: [PATCH] LunaCON: readarrayfromfile: fail silently if file can't be opened. git-svn-id: https://svn.eduke32.com/eduke32@3602 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/lunatic/control.lua | 28 +++++++++++++++------- polymer/eduke32/source/lunatic/lunacon.lua | 2 +- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/polymer/eduke32/source/lunatic/control.lua b/polymer/eduke32/source/lunatic/control.lua index d39276669..0718a5301 100644 --- a/polymer/eduke32/source/lunatic/control.lua +++ b/polymer/eduke32/source/lunatic/control.lua @@ -1225,7 +1225,11 @@ function _cansee(aci, ps) end function _canseespr(s1, s2) - return cansee(sprite[s1], sprite[s1].sectnum, sprite[s2], sprite[s2].sectnum) and 1 or 0 + local spr1, spr2 = sprite[s1], sprite[s2] + -- Redundant, but points the error messages to the CON code: + check_sector_idx(spr1.sectnum) + check_sector_idx(spr2.sectnum) + return cansee(spr1, spr1.sectnum, spr2, spr2.sectnum) and 1 or 0 end -- TODO: replace ivec3 allocations with stores to a static ivec3, like in @@ -1742,17 +1746,19 @@ local function gamearray_file_common(qnum, writep) if (writep) then f, errmsg = io.open(fn) - else - f = kopen4load(fn, 0) - end - - if (f == nil) then - if (not writep) then - error(format([[failed opening "%s" for reading: %s]], fn, errmsg), 3) - else + if (f == nil) then -- file, numints, isnewgar, filename return nil, nil, true, fn end + else + f, errmsg = kopen4load(fn, 0) + if (f == nil) then + if (f==false) then + error(format([[failed opening "%s" for reading: %s]], fn, errmsg), 3) + else + return + end + end end local fsize = assert(f:seek("end")) @@ -1813,6 +1819,10 @@ local gamearray_methods = { read = function(gar, qnum) local f, nelts, isnewgar = gamearray_file_common(qnum, false) + if (f==nil) then + return + end + assert(f:seek("set")) local ints = f:read_le_int32(nelts) if (ints == nil) then diff --git a/polymer/eduke32/source/lunatic/lunacon.lua b/polymer/eduke32/source/lunatic/lunacon.lua index dc2376a61..1baf42e10 100644 --- a/polymer/eduke32/source/lunatic/lunacon.lua +++ b/polymer/eduke32/source/lunatic/lunacon.lua @@ -2132,7 +2132,7 @@ local Cinner = { getarraysize = cmd(GARI,W) / "%2=%1._size", readarrayfromfile = cmd(GARI,D) - / "%1:read(%2)", + / "%1:read(%2,nil)", -- false: error on no file, nil: don't. writearraytofile = cmd(GARI,D) / "%1:write(%2)",