Hi all, I’m trying to catch any final errors at the end of my program right before SDL_Quit(). I thought it would give me a NULL value, but I get a ‘:’ instead.
const char *err_str = SDL_GetError();
if (err_str != NULL)
ErrorFile("Last error if any: ", err_str);
ErrorFile just writes two strings to a text file, nothing special. I get my "Last error if any: " string and a single ‘:’. Is this the intended output for no errors? Can I reliably test against this? It looks like there might be spaces mixed in too.
SDL_GetError() isn’t meant to be used to test for errors, just to fetch a human-readable string if an error occurs.
The docs specifically say not to use it for testing for errors:
You should not use the results of SDL_GetError() to decide if an error has occurred! Sometimes SDL will set an error string even when reporting success.
So don’t call SDL_GetError() unless an SDL function actually returns an error condition.
Well, there’s a single case in SDL2 where you have to do this . When SDL_RWread returns 0, it could be an error or EOF, SDL_strcmp(SDL_GetError(), "") != 0 is the only way to find out. You also have to call SDL_ClearError() just before read to ensure there’s no previous error in there. This hack is used in SDL_LoadBMP_RW
Thanks for the replies. This was only intended to catch any errors I might have missed during program execution. I’ll just use it for testing and remove it from any final release.