LunaCON: readarrayfromfile: fail silently if file can't be opened.

git-svn-id: https://svn.eduke32.com/eduke32@3602 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2013-03-24 18:55:05 +00:00
parent c7d97d55ec
commit 3a1c590572
2 changed files with 20 additions and 10 deletions

View file

@ -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
-- 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

View file

@ -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)",