From cda38e03ed8a6dc407319e1363ad710f581de662 Mon Sep 17 00:00:00 2001 From: Selmar Kok Date: Wed, 22 Aug 2018 18:26:10 +0200 Subject: [PATCH 1/2] change from warning to error for missing bin files --- tiny_gltf.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tiny_gltf.h b/tiny_gltf.h index fb8070d..d00be44 100644 --- a/tiny_gltf.h +++ b/tiny_gltf.h @@ -1257,8 +1257,8 @@ static bool LoadExternalFile(std::vector *out, std::string *err, std::string filepath = FindFile(paths, filename, fs); if (filepath.empty() || filename.empty()) { - if (warn) { - (*warn) += "File not found : " + filename + "\n"; + if (err) { + (*err) += "File not found : " + filename + "\n"; } return false; } From e3b3fa9eb663468e96f200754eed9b003501ef4f Mon Sep 17 00:00:00 2001 From: Selmar Kok Date: Wed, 22 Aug 2018 19:04:21 +0200 Subject: [PATCH 2/2] add required parameter to LoadExternalFile --- tiny_gltf.h | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/tiny_gltf.h b/tiny_gltf.h index d00be44..3d18c48 100644 --- a/tiny_gltf.h +++ b/tiny_gltf.h @@ -1238,7 +1238,7 @@ std::string base64_decode(std::string const &encoded_string) { static bool LoadExternalFile(std::vector *out, std::string *err, std::string *warn, const std::string &filename, - const std::string &basedir, size_t reqBytes, + const std::string &basedir, bool required, size_t reqBytes, bool checkSize, FsCallbacks *fs) { if (fs == nullptr || fs->FileExists == nullptr || fs->ExpandFilePath == nullptr || fs->ReadWholeFile == nullptr) { @@ -1249,6 +1249,8 @@ static bool LoadExternalFile(std::vector *out, std::string *err, return false; } + std::string* failMsgOut = required ? err : warn; + out->clear(); std::vector paths; @@ -1257,8 +1259,8 @@ static bool LoadExternalFile(std::vector *out, std::string *err, std::string filepath = FindFile(paths, filename, fs); if (filepath.empty() || filename.empty()) { - if (err) { - (*err) += "File not found : " + filename + "\n"; + if (failMsgOut) { + (*failMsgOut) += "File not found : " + filename + "\n"; } return false; } @@ -1268,15 +1270,17 @@ static bool LoadExternalFile(std::vector *out, std::string *err, bool fileRead = fs->ReadWholeFile(&buf, &fileReadErr, filepath, fs->user_data); if (!fileRead) { - if (err) { - (*err) += "File read error : " + filepath + " : " + fileReadErr + "\n"; + if (failMsgOut) { + (*failMsgOut) += "File read error : " + filepath + " : " + fileReadErr + "\n"; } return false; } size_t sz = buf.size(); if (sz == 0) { - (*err) += "File is empty : " + filepath + "\n"; + if(failMsgOut) { + (*failMsgOut) += "File is empty : " + filepath + "\n"; + } return false; } @@ -1288,8 +1292,8 @@ static bool LoadExternalFile(std::vector *out, std::string *err, std::stringstream ss; ss << "File size mismatch : " << filepath << ", requestedBytes " << reqBytes << ", but got " << sz << std::endl; - if (err) { - (*err) += ss.str(); + if (failMsgOut) { + (*failMsgOut) += ss.str(); } return false; } @@ -2171,7 +2175,7 @@ static bool ParseImage(Image *image, std::string *err, std::string *warn, #ifdef TINYGLTF_NO_EXTERNAL_IMAGE return true; #endif - if (!LoadExternalFile(&img, err, warn, uri, basedir, 0, false, fs)) { + if (!LoadExternalFile(&img, err, warn, uri, basedir, false, 0, false, fs)) { if (warn) { (*warn) += "Failed to load external 'uri' for image parameter\n"; } @@ -2266,7 +2270,7 @@ static bool ParseBuffer(Buffer *buffer, std::string *err, const json &o, } else { // External .bin file. if (!LoadExternalFile(&buffer->data, err, /* warn */ nullptr, buffer->uri, - basedir, bytes, true, fs)) { + basedir, true, bytes, true, fs)) { return false; } } @@ -2308,7 +2312,7 @@ static bool ParseBuffer(Buffer *buffer, std::string *err, const json &o, } else { // Assume external .bin file. if (!LoadExternalFile(&buffer->data, err, /* warn */ nullptr, buffer->uri, - basedir, bytes, true, fs)) { + basedir, true, bytes, true, fs)) { return false; } }