Format error message.

Add regression test of issue-416.
This commit is contained in:
Syoyo Fujita 2023-04-23 21:47:31 +09:00
parent b534b6b0d8
commit 877d856e71
3 changed files with 26 additions and 6 deletions

1
tests/issue-416.gltf Normal file
View File

@ -0,0 +1 @@
{"images":[{"uri":"%!QAAAQAAA5"}],"asset":{"version":""}}

View File

@ -738,3 +738,22 @@ TEST_CASE("filesize-check", "[issue-416]") {
REQUIRE(false == ret);
}
TEST_CASE("load-issue-416-model", "[issue-416]") {
tinygltf::Model model;
tinygltf::TinyGLTF ctx;
std::string err;
std::string warn;
bool ret = ctx.LoadASCIIFromFile(&model, &err, &warn, "issue-416.gltf");
if (!warn.empty()) {
std::cout << "WARN:" << warn << std::endl;
}
if (!err.empty()) {
std::cerr << "ERR:" << err << std::endl;
}
// external file load fails, but reading glTF itself is ok.
REQUIRE(true == ret);
}

View File

@ -4177,8 +4177,8 @@ static bool ParseImage(Image *image, const int image_idx, std::string *err,
if (!uri_cb->decode(uri, &decoded_uri, uri_cb->user_data)) {
if (warn) {
(*warn) += "Failed to decode 'uri' for image[" +
std::to_string(image_idx) + "] name = [" + image->name +
"]\n";
std::to_string(image_idx) + "] name = \"" + image->name +
"\"\n";
}
// Image loading failure is not critical to overall gltf loading.
@ -4190,8 +4190,8 @@ static bool ParseImage(Image *image, const int image_idx, std::string *err,
/* checksize */ false, /* max file size */ max_file_size, fs)) {
if (warn) {
(*warn) += "Failed to load external 'uri' for image[" +
std::to_string(image_idx) + "] name = [" + decoded_uri +
"]\n";
std::to_string(image_idx) + "] name = \"" + decoded_uri +
"\"\n";
}
// If the image cannot be loaded, keep uri as image->uri.
return true;
@ -4200,8 +4200,8 @@ static bool ParseImage(Image *image, const int image_idx, std::string *err,
if (img.empty()) {
if (warn) {
(*warn) += "Image data is empty for image[" +
std::to_string(image_idx) + "] name = [" + image->name +
"] \n";
std::to_string(image_idx) + "] name = \"" + image->name +
"\" \n";
}
return false;
}