nothings / stb

stb single-file public domain libraries for C/C++
https://twitter.com/nothings
Other
25.99k stars 7.67k forks source link

stb_image | stbi_failure_reason() problem #1510

Closed defini7 closed 11 months ago

defini7 commented 11 months ago

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() : "") Screenshot

N-R-K commented 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

N-R-K commented 11 months ago

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);
nothings commented 11 months ago

Sure. I mean, it shouldn't be necessary, but such is life.