diff --git a/examples/gl_viewer/gl_viewer.cpp b/examples/gl_viewer/gl_viewer.cpp index f694a357d..a66a591f6 100644 --- a/examples/gl_viewer/gl_viewer.cpp +++ b/examples/gl_viewer/gl_viewer.cpp @@ -529,7 +529,7 @@ bool loadImage(Viewer* viewer, fastgltf::Image& image) { }, [&](fastgltf::sources::Array& vector) { int width, height, nrChannels; - unsigned char *data = stbi_load_from_memory(vector.bytes.data(), static_cast(vector.bytes.size()), &width, &height, &nrChannels, 4); + unsigned char *data = stbi_load_from_memory(reinterpret_cast(vector.bytes.data()), static_cast(vector.bytes.size()), &width, &height, &nrChannels, 4); glTextureStorage2D(texture, getLevelCount(width, height), GL_RGBA8, width, height); glTextureSubImage2D(texture, 0, 0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data); stbi_image_free(data); @@ -545,7 +545,8 @@ bool loadImage(Viewer* viewer, fastgltf::Image& image) { [](auto& arg) {}, [&](fastgltf::sources::Array& vector) { int width, height, nrChannels; - unsigned char* data = stbi_load_from_memory(vector.bytes.data() + bufferView.byteOffset, static_cast(bufferView.byteLength), &width, &height, &nrChannels, 4); + unsigned char* data = stbi_load_from_memory(reinterpret_cast(vector.bytes.data() + bufferView.byteOffset), + static_cast(bufferView.byteLength), &width, &height, &nrChannels, 4); glTextureStorage2D(texture, getLevelCount(width, height), GL_RGBA8, width, height); glTextureSubImage2D(texture, 0, 0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data); stbi_image_free(data); diff --git a/include/fastgltf/types.hpp b/include/fastgltf/types.hpp index e3109eb4a..37c00b109 100644 --- a/include/fastgltf/types.hpp +++ b/include/fastgltf/types.hpp @@ -1520,13 +1520,13 @@ namespace fastgltf { }; FASTGLTF_EXPORT struct Array { - StaticVector bytes; + StaticVector bytes; MimeType mimeType = MimeType::None; }; /** @note This type is not used by the fastgltf parser and is only used for exporting. Use sources::Array instead when importing intead. */ FASTGLTF_EXPORT struct Vector { - std::vector bytes; + std::vector bytes; MimeType mimeType = MimeType::None; }; diff --git a/src/fastgltf.cpp b/src/fastgltf.cpp index d6ecef7c6..9844d9a99 100644 --- a/src/fastgltf.cpp +++ b/src/fastgltf.cpp @@ -725,19 +725,19 @@ fg::Expected fg::Parser::decodeDataUri(URIView& uri) const noexc } } - // Decode the base64 data into a traditional vector - auto padding = base64::getPadding(encodedData); - fg::StaticVector uriData(base64::getOutputSize(encodedData.size(), padding)); - if (config.decodeCallback != nullptr) { - config.decodeCallback(encodedData, uriData.data(), padding, uriData.size(), config.userPointer); - } else { - base64::decode_inplace(encodedData, uriData.data(), padding); - } + // Decode the base64 data into a traditional vector + auto padding = base64::getPadding(encodedData); + fg::StaticVector uriData(base64::getOutputSize(encodedData.size(), padding)); + if (config.decodeCallback != nullptr) { + config.decodeCallback(encodedData, reinterpret_cast(uriData.data()), padding, uriData.size(), config.userPointer); + } else { + base64::decode_inplace(encodedData, reinterpret_cast(uriData.data()), padding); + } - sources::Array source { + sources::Array source { std::move(uriData), getMimeTypeFromString(mime), - }; + }; return { std::move(source) }; } @@ -856,19 +856,19 @@ namespace fastgltf { } } - std::pair, ComponentType> writeIndices(PrimitiveType type, std::size_t indexCount, std::size_t primitiveCount) { + std::pair, ComponentType> writeIndices(PrimitiveType type, std::size_t indexCount, std::size_t primitiveCount) { if (indexCount < 255) { - StaticVector generatedIndices(indexCount); - span indices(generatedIndices.data(), generatedIndices.size()); + StaticVector generatedIndices(indexCount * sizeof(std::uint8_t)); + span indices(reinterpret_cast(generatedIndices.data()), generatedIndices.size() / sizeof(std::uint8_t)); writeIndices(type, indices, primitiveCount); return std::make_pair(generatedIndices, ComponentType::UnsignedByte); } else if (indexCount < 65535) { - StaticVector generatedIndices(indexCount * sizeof(std::uint16_t)); + StaticVector generatedIndices(indexCount * sizeof(std::uint16_t)); span indices(reinterpret_cast(generatedIndices.data()), generatedIndices.size() / sizeof(std::uint16_t)); writeIndices(type, indices, primitiveCount); return std::make_pair(generatedIndices, ComponentType::UnsignedShort); } else { - StaticVector generatedIndices(indexCount * sizeof(std::uint32_t)); + StaticVector generatedIndices(indexCount * sizeof(std::uint32_t)); span indices(reinterpret_cast(generatedIndices.data()), generatedIndices.size() / sizeof(std::uint32_t)); writeIndices(type, indices, primitiveCount); return std::make_pair(generatedIndices, ComponentType::UnsignedInt); @@ -3891,12 +3891,12 @@ fg::Expected fg::Parser::loadGltfBinary(GltfDataGetter& data, fs::pat glbBuffer = sources::CustomBuffer{info.customId, MimeType::None}; } } else { - StaticVector binaryData(binaryChunk.chunkLength); + StaticVector binaryData(binaryChunk.chunkLength); data.read(binaryData.data(), binaryChunk.chunkLength); sources::Array vectorData = { - std::move(binaryData), - MimeType::GltfBuffer, + std::move(binaryData), + MimeType::GltfBuffer, }; glbBuffer = std::move(vectorData); } diff --git a/src/io.cpp b/src/io.cpp index 7f797d485..ef9cc2f02 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -456,7 +456,7 @@ fg::Expected fg::Parser::loadFileFromUri(URIView& uri) const noe } } - StaticVector data(static_cast(length)); + StaticVector data(static_cast(length)); file.read(reinterpret_cast(data.data()), length); sources::Array arraySource { std::move(data),