Error when writing image (errno 13 returned by fopen_s) #1448
-
For a little context, it happens when writing images in a c++ app. I used a debugger and tracked to line 323 in std_image_write.h which is the following part of code: #elif defined(_MSC_VER) && _MSC_VER >= 1400 Here, fopen_s returns errno 13 which, from what I read, is a permission error. I use visual studio as an IDE and cmake for the build system. I tried running visual studio as admin and the executable as admin but that did not work. I also tried swapping fopen_s with fopen and it works correctly (opens files successfully and writes into them). Is there any way to fix this without modifying the library itself? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
this is surely not a problem with stb library. you should try calling also, good luck. |
Beta Was this translation helpful? Give feedback.
-
Turns out the files I wanted to write to were already opened in a std::ofstream which I forgot to .close() before calling write_image functions (the write function being called in the same scope as the stream object). And apparently there was no problem opening the files again with std::ofstream and fopen but fopen_s returned a permission error. Was a big pain figuring this out tho. Anyways, thanks for answering and for the awesome library. |
Beta Was this translation helpful? Give feedback.
this is surely not a problem with stb library. you should try calling
fopen_s
andfopen
from your own code with the same filename (mode is the string "wb") and see what behaviors you get.also,
fopen
andfopen_s
are not supposed to behave differently with respect to permissions, so that's weird.good luck.