Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Content of the embedded buffer is not written to the GLB file when exporting #52

Closed
Cyphall opened this issue Mar 7, 2024 · 2 comments
Labels
bug Something isn't working done Everything has been addressed

Comments

@Cyphall
Copy link
Contributor

Cyphall commented Mar 7, 2024

When exporting an asset as GLB, the first buffer is correctly flagged as embedded and no .bin is created, but the content of said buffer is never actually written to the GLB file.

This is caused by missing const qualifiers in the parameter of the visitor handlers:

fastgltf/src/fastgltf.cpp

Lines 5515 to 5539 in 753b161

if (withEmbeddedBuffer) {
const auto& buffer = asset.buffers.front();
BinaryGltfChunk dataChunk;
dataChunk.chunkType = binaryGltfDataChunkMagic;
dataChunk.chunkLength = static_cast<std::uint32_t>(alignUp(buffer.byteLength, 4));
write(&dataChunk, sizeof dataChunk);
for (std::size_t i = 0; i < buffer.byteLength % 4; ++i) {
static constexpr std::uint8_t zero = 0x0U;
write(&zero, sizeof zero);
}
std::visit(visitor {
[](auto arg) {},
[&](sources::Array& vector) {
write(vector.bytes.data(), buffer.byteLength);
},
[&](sources::Vector& vector) {
write(vector.bytes.data(), buffer.byteLength);
},
[&](sources::ByteView& byteView) {
write(byteView.bytes.data(), buffer.byteLength);
},
}, buffer.data);
}

Since buffer is const, buffer.data is also const, but none of the visitor handlers take a const value as parameter so they never get called.
All cases are currently routed to the default handler [](auto arg) {}.

@Cyphall Cyphall changed the title Content of embedded buffer is not written to the GLB file when exporting Content of the embedded buffer is not written to the GLB file when exporting Mar 7, 2024
@spnda
Copy link
Owner

spnda commented Mar 8, 2024

I didn't have any time yesterday to tend to your issues, but I quickly tried and tested this.

Since buffer is const, buffer.data is also const, but none of the visitor handlers take a const value as parameter so they never get called.

If I remember correctly specifying them as const didn't fix the issue. Or did that work locally for you? Also, I'll have to figure out some tests that verify that the buffer was correctly written, as that isn't covered right now.

@Cyphall
Copy link
Contributor Author

Cyphall commented Mar 8, 2024

Or did that work locally for you?

Yes, I have added the missing const qualifiers locally and it now work as expected.

@spnda spnda added the bug Something isn't working label Mar 8, 2024
@spnda spnda closed this as completed in 7b72592 Mar 8, 2024
@spnda spnda added the done Everything has been addressed label Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working done Everything has been addressed
Projects
None yet
Development

No branches or pull requests

2 participants