mirror of
https://github.com/syoyo/tinygltf.git
synced 2026-06-08 11:13:50 +00:00
Compare commits
29 Commits
v2.9.4
...
copilot/up
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
797bf0e023 | ||
|
|
10ac914244 | ||
|
|
dc6dddac98 | ||
|
|
b548191e41 | ||
|
|
17287c7fcf | ||
|
|
6c948d5bc3 | ||
|
|
d4a4a1b27a | ||
|
|
3d5453ecd0 | ||
|
|
52a453120b | ||
|
|
fc6d78a1b6 | ||
|
|
ae0bac486c | ||
|
|
b19e665747 | ||
|
|
40f6c2b875 | ||
|
|
e8c70dff1d | ||
|
|
1dc37f76ea | ||
|
|
8da66b8ca1 | ||
|
|
81bd50c106 | ||
|
|
6d8bba0d8a | ||
|
|
2aa77e5d0a | ||
|
|
1fac6234d9 | ||
|
|
bcd666fbd4 | ||
|
|
37250b3470 | ||
|
|
7385235e29 | ||
|
|
3564b48760 | ||
|
|
2ad433b68f | ||
|
|
1b517f2b23 | ||
|
|
bd7255e095 | ||
|
|
a5e653e46c | ||
|
|
d530cd410b |
92
.github/instructions/copilot-instructions.md
vendored
Normal file
92
.github/instructions/copilot-instructions.md
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
# Copilot Review Instructions for TinyGLTF
|
||||
|
||||
This document provides guidelines for reviewing code changes in the TinyGLTF repository.
|
||||
|
||||
## Memory Safety
|
||||
|
||||
- **Buffer Overflows**: Check for proper bounds checking when accessing arrays, vectors, and buffers. Verify that buffer sizes are validated before read/write operations.
|
||||
- **Null Pointer Dereferences**: Ensure all pointers are checked for null before dereferencing, especially when handling optional glTF fields.
|
||||
- **Memory Leaks**: Verify proper resource management, including RAII patterns for file handles, image data, and dynamically allocated memory.
|
||||
- **Use-After-Free**: Check for proper lifetime management of objects, especially when dealing with callbacks and asynchronous operations.
|
||||
|
||||
## Error Handling
|
||||
|
||||
- **File I/O**: Verify that all file operations have proper error checking and meaningful error messages.
|
||||
- **JSON Parsing**: Ensure JSON parsing errors are caught and reported with helpful context about the location and nature of the error.
|
||||
- **Resource Loading**: Check that failures in loading images, buffers, and other resources are properly handled and don't cause crashes.
|
||||
- **Error Propagation**: Verify that errors are properly propagated through the call stack with appropriate error messages.
|
||||
|
||||
## glTF 2.0 Specification Compliance
|
||||
|
||||
- **Required Fields**: Ensure all required glTF fields are validated and present.
|
||||
- **Data Types**: Verify that data types match the glTF specification (e.g., component types, accessor types).
|
||||
- **Constraints**: Check that glTF constraints are enforced (e.g., valid ranges for enums, buffer stride requirements).
|
||||
- **Extensions**: Verify proper handling of glTF extensions and that unknown extensions are handled gracefully.
|
||||
- **Validation**: Ensure new features align with the glTF 2.0 specification from the Khronos Group.
|
||||
|
||||
## Cross-Platform Compatibility
|
||||
|
||||
- **Windows**: Check for proper handling of Windows-specific issues (path separators, line endings, file operations).
|
||||
- **Linux**: Verify compatibility with various Linux distributions and compilers (GCC, Clang).
|
||||
- **macOS**: Ensure macOS-specific considerations are addressed (case-sensitive filesystems, Clang compatibility).
|
||||
- **Mobile Platforms**: Consider Android and iOS compatibility where applicable.
|
||||
- **Endianness**: Verify proper handling of byte order when reading binary data.
|
||||
- **Compiler Compatibility**: Ensure code compiles with C++11 standard and supported compilers (MSVC, GCC, Clang).
|
||||
|
||||
## Edge Cases in glTF Parsing
|
||||
|
||||
- **Empty/Minimal Files**: Verify handling of minimal valid glTF files.
|
||||
- **Large Files**: Check for proper handling of large glTF files and buffers without memory exhaustion.
|
||||
- **Malformed Data**: Ensure graceful handling of malformed or invalid glTF data.
|
||||
- **Missing Optional Fields**: Verify correct behavior when optional glTF fields are absent.
|
||||
- **Edge Values**: Check handling of boundary values (e.g., maximum buffer sizes, extreme floating-point values).
|
||||
- **Base64 Encoding**: Verify proper handling of base64-encoded data URIs and invalid encodings.
|
||||
|
||||
## Backwards Compatibility
|
||||
|
||||
- **API Changes**: Ensure public API changes maintain backwards compatibility or are properly deprecated.
|
||||
- **Breaking Changes**: Flag any breaking changes for major version updates and document migration paths.
|
||||
- **Binary Compatibility**: Consider ABI stability for header-only library changes.
|
||||
- **Default Behavior**: Verify that default behavior of existing functionality remains unchanged.
|
||||
|
||||
## Performance Considerations
|
||||
|
||||
- **Parsing Performance**: Check for unnecessary copies, redundant allocations, and inefficient algorithms in parsing logic.
|
||||
- **Memory Usage**: Verify efficient memory usage, especially when loading large glTF files.
|
||||
- **I/O Operations**: Ensure efficient file reading and minimize unnecessary disk access.
|
||||
- **String Operations**: Check for efficient string handling (use of string_view, move semantics).
|
||||
- **STL Usage**: Verify appropriate use of STL containers and algorithms.
|
||||
|
||||
## Documentation
|
||||
|
||||
- **Public API**: Ensure all public functions, classes, and methods have clear documentation comments.
|
||||
- **Parameters**: Verify that function parameters are documented, including expected ranges and constraints.
|
||||
- **Return Values**: Document return values and possible error conditions.
|
||||
- **Examples**: Check that complex features include usage examples.
|
||||
- **Changelog**: Verify that significant changes are documented in release notes or changelog.
|
||||
|
||||
## Testing
|
||||
|
||||
- **Test Coverage**: Ensure new features include appropriate unit tests or integration tests.
|
||||
- **Edge Cases**: Verify that tests cover edge cases and error conditions.
|
||||
- **Cross-Platform Tests**: Check that tests run on all supported platforms.
|
||||
- **Regression Tests**: Ensure bug fixes include regression tests to prevent recurrence.
|
||||
- **Sample Files**: Verify that changes are tested with various valid and invalid glTF sample files.
|
||||
|
||||
## Code Style Consistency
|
||||
|
||||
- **Header-Only Pattern**: Maintain the header-only library structure.
|
||||
- **Naming Conventions**: Follow existing naming conventions (CamelCase for types, snake_case for functions where applicable).
|
||||
- **Formatting**: Adhere to the existing code formatting style (check `.clang-format` if available).
|
||||
- **Include Guards**: Verify proper include guards and header organization.
|
||||
- **Namespace Usage**: Ensure proper use of the `tinygltf` namespace.
|
||||
- **Comments**: Maintain consistent comment style with existing code.
|
||||
- **C++11 Compliance**: Verify that code uses C++11 features appropriately and doesn't require newer standards unless specified.
|
||||
|
||||
## Additional Considerations
|
||||
|
||||
- **Third-Party Dependencies**: Minimize new dependencies; prefer existing dependencies (json.hpp, stb_image).
|
||||
- **Warnings**: Ensure code compiles without warnings on supported compilers.
|
||||
- **const Correctness**: Verify proper use of const for parameters and methods.
|
||||
- **RAII**: Prefer RAII patterns for resource management over manual cleanup.
|
||||
- **noexcept**: Use noexcept appropriately for move constructors and move assignment operators.
|
||||
330
.github/workflows/ci.yml
vendored
Normal file
330
.github/workflows/ci.yml
vendored
Normal file
@@ -0,0 +1,330 @@
|
||||
name: Comprehensive CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- release
|
||||
- devel
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
- release
|
||||
- devel
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
# Linux x64 - GCC
|
||||
linux-gcc-x64:
|
||||
runs-on: ubuntu-latest
|
||||
name: Linux x64 (GCC)
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Configure
|
||||
run: cmake -B build -DTINYGLTF_BUILD_LOADER_EXAMPLE=ON
|
||||
|
||||
- name: Build
|
||||
run: cmake --build build
|
||||
|
||||
- name: Run loader_example
|
||||
run: ./build/loader_example models/Cube/Cube.gltf
|
||||
|
||||
- name: Run tests
|
||||
run: ctest --test-dir build --output-on-failure
|
||||
|
||||
# Linux x64 - Clang 21
|
||||
linux-clang-x64:
|
||||
runs-on: ubuntu-24.04
|
||||
name: Linux x64 (Clang 21)
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install Clang 21
|
||||
run: |
|
||||
wget https://apt.llvm.org/llvm.sh
|
||||
chmod +x llvm.sh
|
||||
sudo ./llvm.sh 21
|
||||
|
||||
- name: Configure
|
||||
run: |
|
||||
cmake -B build -DCMAKE_C_COMPILER=clang-21 -DCMAKE_CXX_COMPILER=clang++-21 -DTINYGLTF_BUILD_LOADER_EXAMPLE=ON
|
||||
|
||||
- name: Build
|
||||
run: cmake --build build
|
||||
|
||||
- name: Run loader_example
|
||||
run: |
|
||||
./build/loader_example models/Cube/Cube.gltf
|
||||
|
||||
- name: Run tests
|
||||
run: ctest --test-dir build --output-on-failure
|
||||
|
||||
# Linux ARM64 - GCC (native)
|
||||
linux-arm64:
|
||||
runs-on: ubuntu-24.04-arm
|
||||
name: Linux ARM64 (GCC)
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Configure
|
||||
run: cmake -B build -DTINYGLTF_BUILD_LOADER_EXAMPLE=ON
|
||||
|
||||
- name: Build
|
||||
run: cmake --build build
|
||||
|
||||
- name: Run loader_example
|
||||
run: ./build/loader_example models/Cube/Cube.gltf
|
||||
|
||||
- name: Run tests
|
||||
run: ctest --test-dir build --output-on-failure
|
||||
|
||||
# macOS ARM64 Apple Silicon
|
||||
macos-arm64:
|
||||
runs-on: macos-14
|
||||
name: macOS ARM64 Apple Silicon (Clang)
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Configure
|
||||
run: cmake -B build -DTINYGLTF_BUILD_LOADER_EXAMPLE=ON
|
||||
|
||||
- name: Build
|
||||
run: cmake --build build
|
||||
|
||||
- name: Run loader_example
|
||||
run: ./build/loader_example models/Cube/Cube.gltf
|
||||
|
||||
- name: Run tests
|
||||
run: ctest --test-dir build --output-on-failure
|
||||
|
||||
# Windows x64 - MSVC
|
||||
windows-msvc-x64:
|
||||
runs-on: windows-latest
|
||||
name: Windows x64 (MSVC)
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Configure
|
||||
run: |
|
||||
mkdir build
|
||||
cd build
|
||||
cmake -G "Visual Studio 17 2022" -A x64 -DTINYGLTF_BUILD_LOADER_EXAMPLE=On -DTINYGLTF_BUILD_GL_EXAMPLES=Off -DTINYGLTF_BUILD_VALIDATOR_EXAMPLE=Off ..
|
||||
|
||||
- name: Build
|
||||
run: cmake --build build --config Release
|
||||
|
||||
- name: Run loader_example
|
||||
run: |
|
||||
.\build\Release\loader_example.exe models\Cube\Cube.gltf
|
||||
|
||||
- name: Run tests
|
||||
run: ctest --test-dir build -C Release --output-on-failure
|
||||
|
||||
# Windows x86 - MSVC
|
||||
windows-msvc-x86:
|
||||
runs-on: windows-latest
|
||||
name: Windows x86 (MSVC)
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Configure
|
||||
run: |
|
||||
mkdir build
|
||||
cd build
|
||||
cmake -G "Visual Studio 17 2022" -A Win32 -DTINYGLTF_BUILD_LOADER_EXAMPLE=On -DTINYGLTF_BUILD_GL_EXAMPLES=Off -DTINYGLTF_BUILD_VALIDATOR_EXAMPLE=Off ..
|
||||
|
||||
- name: Build
|
||||
run: cmake --build build --config Release
|
||||
|
||||
- name: Run tests
|
||||
run: ctest --test-dir build -C Release --output-on-failure
|
||||
|
||||
# Windows ARM64 - MSVC (cross-compile)
|
||||
windows-msvc-arm64:
|
||||
runs-on: windows-latest
|
||||
name: Windows ARM64 (MSVC) - Cross-compile
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Configure
|
||||
run: |
|
||||
mkdir build
|
||||
cd build
|
||||
cmake -G "Visual Studio 17 2022" -A ARM64 -DTINYGLTF_BUILD_LOADER_EXAMPLE=On -DTINYGLTF_BUILD_GL_EXAMPLES=Off -DTINYGLTF_BUILD_VALIDATOR_EXAMPLE=Off ..
|
||||
|
||||
- name: Build
|
||||
run: cmake --build build --config Release
|
||||
|
||||
# Windows MinGW - MSYS2
|
||||
windows-mingw-msys2:
|
||||
runs-on: windows-latest
|
||||
name: Windows x64 (MinGW MSYS2)
|
||||
defaults:
|
||||
run:
|
||||
shell: msys2 {0}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup MSYS2
|
||||
uses: msys2/setup-msys2@v2
|
||||
with:
|
||||
msystem: UCRT64
|
||||
install: base-devel
|
||||
pacboy: >-
|
||||
cc:p cmake:p ninja:p
|
||||
update: true
|
||||
release: false
|
||||
|
||||
- name: Build with CMake
|
||||
run: |
|
||||
cmake -G"Ninja" -S . -B build
|
||||
cmake --build build
|
||||
|
||||
- name: Run loader_example
|
||||
run: |
|
||||
./build/loader_example models/Cube/Cube.gltf
|
||||
|
||||
- name: Run tests
|
||||
run: ctest --test-dir build --output-on-failure
|
||||
|
||||
# Linux -> Windows MinGW Cross-compile
|
||||
linux-mingw-cross:
|
||||
runs-on: ubuntu-latest
|
||||
name: Linux→Windows (MinGW Cross) - Build Only
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install MinGW
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y build-essential mingw-w64
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
x86_64-w64-mingw32-g++ -std=c++11 -o loader_example.exe loader_example.cc
|
||||
|
||||
# Special Configuration: No Exceptions
|
||||
linux-noexception:
|
||||
runs-on: ubuntu-latest
|
||||
name: Linux x64 (GCC) - No Exceptions
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Build loader_example
|
||||
run: |
|
||||
g++ -DTINYGLTF_NOEXCEPTION -std=c++11 -o loader_example loader_example.cc
|
||||
|
||||
- name: Run loader_example
|
||||
run: |
|
||||
./loader_example models/Cube/Cube.gltf
|
||||
|
||||
- name: Build and run unit tests
|
||||
run: |
|
||||
cd tests
|
||||
g++ -DTINYGLTF_NOEXCEPTION -I../ -std=c++11 -g -O0 -o tester_noexcept tester.cc
|
||||
./tester_noexcept
|
||||
|
||||
# Special Configuration: Header-Only Mode
|
||||
linux-header-only:
|
||||
runs-on: ubuntu-latest
|
||||
name: Linux x64 (GCC) - Header-Only Mode
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Build with CMake Header-Only
|
||||
run: |
|
||||
mkdir build
|
||||
cmake -B build -DTINYGLTF_HEADER_ONLY=ON -DTINYGLTF_BUILD_LOADER_EXAMPLE=ON
|
||||
cmake --build build
|
||||
|
||||
- name: Run loader_example
|
||||
run: |
|
||||
./build/loader_example models/Cube/Cube.gltf
|
||||
|
||||
- name: Run tests
|
||||
run: ctest --test-dir build --output-on-failure
|
||||
|
||||
# Special Configuration: RapidJSON Backend
|
||||
linux-rapidjson:
|
||||
runs-on: ubuntu-latest
|
||||
name: Linux x64 (GCC) - RapidJSON Backend
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Clone RapidJSON
|
||||
run: |
|
||||
git clone https://github.com/Tencent/rapidjson
|
||||
|
||||
- name: Configure
|
||||
run: |
|
||||
cmake -B build -DTINYGLTF_USE_RAPIDJSON=ON -DTINYGLTF_BUILD_LOADER_EXAMPLE=ON -DCMAKE_PREFIX_PATH=$PWD/rapidjson
|
||||
|
||||
- name: Build
|
||||
run: cmake --build build
|
||||
|
||||
- name: Run loader_example
|
||||
run: |
|
||||
./build/loader_example models/Cube/Cube.gltf
|
||||
|
||||
- name: Run tests
|
||||
run: ctest --test-dir build --output-on-failure
|
||||
|
||||
# Special Configuration: AddressSanitizer
|
||||
linux-asan:
|
||||
runs-on: ubuntu-latest
|
||||
name: Linux x64 (Clang) - AddressSanitizer
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Build loader_example with ASan
|
||||
run: |
|
||||
clang++ -fsanitize=address -std=c++11 -g -O1 -o loader_example loader_example.cc
|
||||
|
||||
- name: Run loader_example
|
||||
run: |
|
||||
./loader_example models/Cube/Cube.gltf
|
||||
|
||||
- name: Build and run unit tests with ASan
|
||||
run: |
|
||||
cd tests
|
||||
clang++ -fsanitize=address -I../ -std=c++11 -g -O1 -o tester tester.cc
|
||||
./tester
|
||||
|
||||
# Special Configuration: UndefinedBehaviorSanitizer
|
||||
linux-ubsan:
|
||||
runs-on: ubuntu-latest
|
||||
name: Linux x64 (Clang) - UndefinedBehaviorSanitizer
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Build loader_example with UBSan
|
||||
run: |
|
||||
clang++ -fsanitize=undefined -std=c++11 -g -O1 -o loader_example loader_example.cc
|
||||
|
||||
- name: Run loader_example
|
||||
run: |
|
||||
./loader_example models/Cube/Cube.gltf
|
||||
|
||||
- name: Build and run unit tests with UBSan
|
||||
run: |
|
||||
cd tests
|
||||
clang++ -fsanitize=undefined -I../ -std=c++11 -g -O1 -o tester tester.cc
|
||||
./tester
|
||||
@@ -14,6 +14,7 @@ option(TINYGLTF_BUILD_LOADER_EXAMPLE "Build loader_example(load glTF and dump in
|
||||
option(TINYGLTF_BUILD_GL_EXAMPLES "Build GL exampels(requires glfw, OpenGL, etc)" OFF)
|
||||
option(TINYGLTF_BUILD_VALIDATOR_EXAMPLE "Build validator exampe" OFF)
|
||||
option(TINYGLTF_BUILD_BUILDER_EXAMPLE "Build glTF builder example" OFF)
|
||||
option(TINYGLTF_BUILD_TESTS "Build unit tests" OFF)
|
||||
option(TINYGLTF_HEADER_ONLY "On: header-only mode. Off: create tinygltf library(No TINYGLTF_IMPLEMENTATION required in your project)" OFF)
|
||||
option(TINYGLTF_INSTALL "Install tinygltf files during install step. Usually set to OFF if you include tinygltf through add_subdirectory()" ON)
|
||||
option(TINYGLTF_INSTALL_VENDOR "Install vendored nlohmann/json and nothings/stb headers" ON)
|
||||
@@ -37,6 +38,16 @@ if (TINYGLTF_BUILD_BUILDER_EXAMPLE)
|
||||
add_subdirectory ( examples/build-gltf )
|
||||
endif (TINYGLTF_BUILD_BUILDER_EXAMPLE)
|
||||
|
||||
if (TINYGLTF_BUILD_TESTS)
|
||||
enable_testing()
|
||||
add_executable(tester tests/tester.cc)
|
||||
target_include_directories(tester PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tests
|
||||
)
|
||||
add_test(NAME tester COMMAND tester WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests)
|
||||
endif (TINYGLTF_BUILD_TESTS)
|
||||
|
||||
#
|
||||
# for add_subdirectory and standalone build
|
||||
#
|
||||
|
||||
@@ -159,9 +159,10 @@ Model model;
|
||||
TinyGLTF loader;
|
||||
std::string err;
|
||||
std::string warn;
|
||||
std::string filename = "input.gltf";
|
||||
|
||||
bool ret = loader.LoadASCIIFromFile(&model, &err, &warn, argv[1]);
|
||||
//bool ret = loader.LoadBinaryFromFile(&model, &err, &warn, argv[1]); // for binary glTF(.glb)
|
||||
bool ret = loader.LoadASCIIFromFile(&model, &err, &warn, filename);
|
||||
//bool ret = loader.LoadBinaryFromFile(&model, &err, &warn, filename); // for binary glTF(.glb)
|
||||
|
||||
if (!warn.empty()) {
|
||||
printf("Warn: %s\n", warn.c_str());
|
||||
@@ -172,8 +173,7 @@ if (!err.empty()) {
|
||||
}
|
||||
|
||||
if (!ret) {
|
||||
printf("Failed to parse glTF\n");
|
||||
return -1;
|
||||
printf("Failed to parse glTF: %s\n", filename.c_str());
|
||||
}
|
||||
```
|
||||
|
||||
@@ -194,7 +194,6 @@ if (!ret) {
|
||||
* `TINYGLTF_NO_INCLUDE_STB_IMAGE `: Disable including `stb_image.h` from within `tiny_gltf.h` because it has been already included before or you want to include it using custom path before including `tiny_gltf.h`.
|
||||
* `TINYGLTF_NO_INCLUDE_STB_IMAGE_WRITE `: Disable including `stb_image_write.h` from within `tiny_gltf.h` because it has been already included before or you want to include it using custom path before including `tiny_gltf.h`.
|
||||
* `TINYGLTF_USE_RAPIDJSON` : Use RapidJSON as a JSON parser/serializer. RapidJSON files are not included in TinyGLTF repo. Please set an include path to RapidJSON if you enable this feature.
|
||||
* `TINYGLTF_USE_CPP14` : Use C++14 feature(requires C++14 compiler). This may give better performance than C++11.
|
||||
|
||||
|
||||
## CMake options
|
||||
|
||||
@@ -1121,8 +1121,10 @@ TEST_CASE("images-as-is", "[issue-487]") {
|
||||
// All the images should have been written to disk with their original data
|
||||
for (const auto& image : model.images) {
|
||||
// Make sure the image files exist
|
||||
std::fstream file(image.uri);
|
||||
CHECK(file.good());
|
||||
{
|
||||
std::fstream file(image.uri);
|
||||
CHECK(file.good());
|
||||
} // Close file before stbi_load (Windows sharing violation fix)
|
||||
#ifndef TINYGLTF_NO_STB_IMAGE
|
||||
// Make sure we can load the images
|
||||
int w = -1, h = -1, component = -1;
|
||||
|
||||
45
tiny_gltf.h
45
tiny_gltf.h
@@ -50,12 +50,6 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
// Auto-detect C++14 standard version
|
||||
#if !defined(TINYGLTF_USE_CPP14) && defined(__cplusplus) && \
|
||||
(__cplusplus >= 201402L)
|
||||
#define TINYGLTF_USE_CPP14
|
||||
#endif
|
||||
|
||||
#ifdef __ANDROID__
|
||||
#ifdef TINYGLTF_ANDROID_LOAD_FROM_ASSETS
|
||||
#include <android/asset_manager.h>
|
||||
@@ -834,20 +828,20 @@ struct Accessor {
|
||||
maxValues; // optional. integer value is promoted to double
|
||||
|
||||
struct Sparse {
|
||||
int count;
|
||||
bool isSparse;
|
||||
int count{0};
|
||||
bool isSparse{false};
|
||||
struct {
|
||||
size_t byteOffset;
|
||||
int bufferView;
|
||||
int componentType; // a TINYGLTF_COMPONENT_TYPE_ value
|
||||
size_t byteOffset{0};
|
||||
int bufferView{-1};
|
||||
int componentType{-1}; // a TINYGLTF_COMPONENT_TYPE_ value
|
||||
Value extras;
|
||||
ExtensionMap extensions;
|
||||
std::string extras_json_string;
|
||||
std::string extensions_json_string;
|
||||
} indices;
|
||||
struct {
|
||||
int bufferView;
|
||||
size_t byteOffset;
|
||||
int bufferView{-1};
|
||||
size_t byteOffset{0};
|
||||
Value extras;
|
||||
ExtensionMap extensions;
|
||||
std::string extras_json_string;
|
||||
@@ -898,11 +892,7 @@ struct Accessor {
|
||||
// unreachable return 0;
|
||||
}
|
||||
|
||||
Accessor()
|
||||
|
||||
{
|
||||
sparse.isSparse = false;
|
||||
}
|
||||
Accessor() = default;
|
||||
DEFAULT_METHODS(Accessor)
|
||||
bool operator==(const tinygltf::Accessor &) const;
|
||||
};
|
||||
@@ -4362,7 +4352,7 @@ static bool ParseImage(Image *image, const int image_idx, std::string *err,
|
||||
// Just only save some information here. Loading actual image data from
|
||||
// bufferView is done after this `ParseImage` function.
|
||||
image->bufferView = bufferView;
|
||||
image->mimeType = mime_type;
|
||||
image->mimeType = std::move( mime_type );
|
||||
image->width = width;
|
||||
image->height = height;
|
||||
|
||||
@@ -5261,7 +5251,7 @@ static bool ParseNode(Node *node, std::string *err, const detail::json &o,
|
||||
if (node->extensions.count("MSFT_lod") != 0) {
|
||||
auto const &msft_lod_ext = node->extensions["MSFT_lod"];
|
||||
if (msft_lod_ext.Has("ids")) {
|
||||
auto idsArr = msft_lod_ext.Get("ids");
|
||||
const auto &idsArr = msft_lod_ext.Get("ids");
|
||||
for (size_t i = 0; i < idsArr.ArrayLen(); ++i) {
|
||||
node->lods.emplace_back(idsArr.Get(i).GetNumberAsInt());
|
||||
}
|
||||
@@ -5290,7 +5280,7 @@ static bool ParseScene(Scene *scene, std::string *err, const detail::json &o,
|
||||
if (scene->extensions.count("KHR_audio") != 0) {
|
||||
auto const &audio_ext = scene->extensions["KHR_audio"];
|
||||
if (audio_ext.Has("emitters")) {
|
||||
auto emittersArr = audio_ext.Get("emitters");
|
||||
const auto &emittersArr = audio_ext.Get("emitters");
|
||||
for (size_t i = 0; i < emittersArr.ArrayLen(); ++i) {
|
||||
scene->audioEmitters.emplace_back(emittersArr.Get(i).GetNumberAsInt());
|
||||
}
|
||||
@@ -5326,7 +5316,7 @@ static bool ParsePbrMetallicRoughness(
|
||||
}
|
||||
return false;
|
||||
}
|
||||
pbr->baseColorFactor = baseColorFactor;
|
||||
pbr->baseColorFactor = std::move( baseColorFactor );
|
||||
}
|
||||
|
||||
{
|
||||
@@ -5478,7 +5468,7 @@ static bool ParseMaterial(Material *material, std::string *err, std::string *war
|
||||
if (material->extensions.count("MSFT_lod") != 0) {
|
||||
auto const &msft_lod_ext = material->extensions["MSFT_lod"];
|
||||
if (msft_lod_ext.Has("ids")) {
|
||||
auto idsArr = msft_lod_ext.Get("ids");
|
||||
const auto &idsArr = msft_lod_ext.Get("ids");
|
||||
for (size_t i = 0; i < idsArr.ArrayLen(); ++i) {
|
||||
material->lods.emplace_back(idsArr.Get(i).GetNumberAsInt());
|
||||
}
|
||||
@@ -6453,6 +6443,15 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, std::string *warn,
|
||||
return false;
|
||||
}
|
||||
const Buffer &buffer = model->buffers[size_t(bufferView.buffer)];
|
||||
if (bufferView.byteOffset >= buffer.data.size()) {
|
||||
if (err) {
|
||||
std::stringstream ss;
|
||||
ss << "image[" << idx << "] bufferView \"" << image.bufferView
|
||||
<< "\" indexed out of bounds of its buffer." << std::endl;
|
||||
(*err) += ss.str();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (LoadImageData == nullptr) {
|
||||
if (err) {
|
||||
|
||||
Reference in New Issue
Block a user