libsdl-org / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
9.52k stars 1.77k forks source link

`SDL_GetWindowSizeInPixels` may fail #10388

Open anyputer opened 2 months ago

anyputer commented 2 months ago

SDL_GetWindowSizeInPixels, SDL_GetWindowSize, SDL_GetRenderOutputSize and similar get size functions can return an error. However, I haven't yet seen any application code checking for the return value of the size getter functions. I can't think of a case where a window doesn't have a size to retrieve. If this behavior makes sense, the documentation could at least elaborate on what "failure" means in this context.

Thanks in advance for looking into this.

AntTheAlchemist commented 2 months ago

Looking at SDL source code, an invalid SDL_Window (or other object) passed to these functions is the only time it'll cause an error. Either null, or a prematurely deleted window would do it. SDL3 has become more bullet-proof (fool proof) lately. Every function is encased in bubble wrap. It's to try to reduce the amount of bug reports and posts caused by app-developer misuse. I personally don't like it because the same SDL_Window (and other objects) will be checked and re-checked multiple times for simple operations, even when it's already been confirmed to be valid. It's getting bloated.

You raise a good point... where do we really have to check for return codes. Wrapping every SDL call in an error check isn't always necessary, if we already know the SDL object is valid.