spnda / fastgltf

A modern C++17 glTF 2.0 library focused on speed, correctness, and usability
https://fastgltf.readthedocs.io/v0.8.x/
MIT License
312 stars 48 forks source link

fastgltf probably shouldn't use tellg to get file sizes, might not always be the file size #17

Closed EvilTrev closed 1 year ago

EvilTrev commented 1 year ago

Seen here for example:

    std::ifstream file(path, std::ios::ate | std::ios::binary);
    auto length = static_cast<std::streamsize>(file.tellg());
    file.seekg(0);

This has some issues, and there is a bunch of discussion here: https://stackoverflow.com/questions/2409504/using-c-filestreams-fstream-how-can-you-determine-the-size-of-a-file

But long, short, if using c++17 or later, then:

   auto length = std::filesystem::file_size( path );
spnda commented 1 year ago

I am aware of this issue and I do use this answer's idea in the GltfDataBuffer. Could you please pinpoint a line where I do use tellg? (I tried looking for tellg in the code on my phone but it doesn't seem to catch the occurences)

Also, is the filesystem method any more exact than what I currently use?