Closed defini7 closed 11 months ago
stbi_failure_reason() returns NULL when there is no error
Calling stbi_failure_reason()
is only meaningful if there was an error. If there was no error, then that function doesn't have any defined behavior.
See this comment: https://github.com/nothings/stb/issues/1317#issuecomment-1094090596
Since at least two people got confused by this already, it's probably not a bad idea to add a more descriptive comment. Something like the following maybe:
// get a VERY brief reason for failure
// on most compilers (and ALL modern mainstream compilers) this is threadsafe
+// NOTE: this function should be called only after an error actually occured.
STBIDEF const char *stbi_failure_reason (void);
Sure. I mean, it shouldn't be necessary, but such is life.
stbi_failure_reason() returns NULL when there is no error, so when i tried to pass result of calling that function to my custom assert function i got a problem. I fixed it by adding that macro:
#define SAFE_STBI_FAILURE_REASON() (stbi_failure_reason() ? stbi_failure_reason() : "")