Skip to content

Commit

Permalink
Format error message.
Browse files Browse the repository at this point in the history
Add regression test of issue-416.
  • Loading branch information
syoyo committed Apr 23, 2023
1 parent b534b6b commit 877d856
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
1 change: 1 addition & 0 deletions tests/issue-416.gltf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"images":[{"uri":"%!QAAAQAAA5"}],"asset":{"version":""}}
19 changes: 19 additions & 0 deletions tests/tester.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
12 changes: 6 additions & 6 deletions tiny_gltf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand All @@ -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;
}
Expand Down

0 comments on commit 877d856

Please sign in to comment.