Closed DanielLorenzLaubwerk closed 4 days ago
Good find!
as_is
flag is somewhat hidden feature and not considered in WriteGltfSceneToFile
, so this is the issue.
We'll probably need to bypass WriteImageData
function when as_is
is set to true:
https://github.com/syoyo/tinygltf/blob/f03fe2657971332916533c03d0c8c751972df9ee/tiny_gltf.h#L3233
something like...
if (!filename.empty() && !image.image.empty()) {
if (image.as_is) {
// serialize to buffer.
} else if (*WriteImageData != nullptr) {
call WriteImageData(...)
}
}
Yes, that looks good.
You can contribute. PR is much appreciated!
I'll take this one. Working in this area of the code anyways.
🙏
Cool, let us know if and when we can help testing anything, @ptc-tgamper!
@ptc-tgamper Would it possible to add this fix to this PR https://github.com/syoyo/tinygltf/pull/491 ? It'd be convenient to add as_is
flag fixes to a single PR.
I can, if you prefer it that way.
Thanks! Yes I prefer it, since I'll bump the minor version of tinygltf once PR #491 has been merged. Putting 'as-is' flag fix to #491 will save redundant version increments
Describe the issue
The tinygltf::Image class contains an
as_is
variable, that indicates that the image data contains an encoded image. The declaration of asas_is
variable says:However, when I store a encoded/compressed image and set the
as_is
flag to true,WriteGltfSceneToFile()
crashes. As far as I can see, the writer ignores theas_is
flag completely and tries to encode the already compressed data anew.To Reproduce
int main() { // Load an image tinygltf::Image image; std::string image_path = "example_image.png"; unsigned char *raw_image = stbi_load(image_path.c_str(), &image.width, &image.height, &image.component, 0);
}