-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sdl: don't return error when reading 0 bytes #784
Conversation
Reaching the end of the file is not an error. This is consistent with stm32/pico.
As Github said, |
Ah right, and |
Ugh SDL_ClearError();
size_t bytes_read = SDL_RWread(file, buffer, 1, length);
if(!SDL_GetError()[0])
return (int32_t)bytes_read; |
This doesn't seem right either. The doc says "call SDL_GetError() for more information." but the doc for SDL_GetError says "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. SDL will not clear the error string for successful API calls. You must check return values for failure cases before you can assume the error string applies." So that means SDL_GetError might report a different error. I don't see how it is possible to tell the difference between EOF and error with this API. |
Yeah, that was part of the "ugh". I did clear the error before the call, but it's still nasty. Maybe we'll just have to rewrite it to not use rwops (as it's only using files anyway)... |
Seems reasonable since the errors are per-thread and nothing else gets called in between. I asked the question on SDL forums: https://discourse.libsdl.org/t/how-to-tell-whether-an-error-happened-in-sdl-rwread/38828 |
0 could mean EOF and not an error, clearing and then checking for an error seems to be the only way to check...
Thank you both! |
Hah, they fixed the "can't tell if EOF or error" problem... in SDL3. |
Here's an easy one. Avoids errors at the end of reading files.