syoyo / tinygltf

Header only C++11 tiny glTF 2.0 library
MIT License
1.94k stars 395 forks source link

WriteGltfSceneToFile (_wopen) might fail when compiling with MinGW (MSYS2) #477

Closed The0Dev closed 3 months ago

The0Dev commented 3 months ago

Describe the issue

The function_wopen might fail to open an existing file created by the previous call to _wopen since the file is created as read-only by default. Passing _S_IREAD | _S_IWRITE as the third argument solves the issue.

To Reproduce Call WriteGltfSceneToFile (WriteBinaryGltfFile) twice.

Expected behaviour

Files should be created with the read and write permissions.

Additional context

A related question on Stackoverflow Microsoft Learn

The pmode argument is required when _O_CREAT is specified

syoyo commented 3 months ago

Interesting. Didn't know _wopen creates a file as read-only by default.

We'll need to add _S_IREAD | _S_IWRITE(or _S_IWRITE alone suffices on Windows) to every _wopen call where file is open for write.

PR is much appreciated!