1) minor error handling improvements (was passing back invalid handle error, instead of the cause; also added a CHECK_ERR)

2) we attempt to load missing files (see bug #32). with the fix above,
CHECK_ERR would fire every run (which it should until the problem is
fixed :P), which is annoying.
Instead, FileUnpacker now checks if the file exists; if not, it throws
immediately and thereby bypasses the VFS error mechanism.

This was SVN commit r1503.
This commit is contained in:
janwas 2004-12-15 14:24:12 +00:00
parent 32854fc162
commit b259381fbf
3 changed files with 13 additions and 2 deletions

View File

@ -1174,8 +1174,7 @@ int tex_load(const char* fn, TexInfo* t)
void* _p = 0;
size_t size;
Handle hm = vfs_load(fn, _p, size);
if(hm <= 0)
return (int)hm;
CHECK_ERR(hm); // (need handle below; can't test return value directly)
// guarantee *_valid routines 4 header bytes
if(size < 4)
{

View File

@ -1672,6 +1672,10 @@ debug_out("vfs_load v_fn=%s\n", v_fn);
p = 0; size = 0; // zeroed in case vfs_open or H_DEREF fails
Handle hf = vfs_open(v_fn, flags);
CHECK_ERR(hf);
// note: if we skip this and have H_DEREF report the error,
// we get "invalid handle" instead of vfs_open's error code.
H_DEREF(hf, VFile, vf);
Handle hm = 0; // return value - handle to memory or error code

View File

@ -26,6 +26,14 @@ CFileUnpacker::CFileUnpacker()
// variety of exceptions for missing files etc
void CFileUnpacker::Read(const char* filename,const char magicstr[4])
{
// avoid vfs_load complaining about missing data files (which happens
// too often). better to check here than squelch internal VFS error
// reporting. we disable this in release mode to avoid a speed hit.
#ifndef NDEBUG
if(!vfs_exists(filename))
throw CFileOpenError();
#endif
// load the whole thing into memory
Handle hm = vfs_load(filename, m_Buf, m_Size);
if(hm <= 0)