libsdl-org / sdl2-compat

An SDL2 compatibility layer that uses SDL3 behind the scenes.
zlib License
80 stars 19 forks source link

Fix broken mode switching due to information loss when casting the mode struct #233

Closed Kontrabant closed 4 weeks ago

Kontrabant commented 4 weeks ago

When entering exclusive fullscreen, SDL3 verifies that the requested mode parameters precisely match a mode exposed by the output, which can cause the mode switch to fail due to the float to int rounding of the refresh rate when converting between the SDL2 and SDL3 mode structs. Instead of casting directly, use the SDL2 mode parameters to try and find the closest matching SDL3 display mode.

This fixes video mode switching for modes with refresh rates that are not precisely an integer, and allows for the removal of the DisplayMode_2to3() function entirely.

Tested to fix both the SDL test suite (testsprite2 with ctrl+enter), and real-world cases such as changing the resolution in vkQuake on displays with refresh rates that are not an exact integer value.