SDL: Work around bug #7038 by limiting mode reset to Win32.

Bug is: "IRIX: X BadMatch when trying to start any 640x480 game".

40e019efd4 introduced resetting the pixel depth
when unloading modes for SDL output. This was required to make mode listing
for OpenGL work on Win8+.

This causes issues on non-Win32 platforms though. SDL might not give us a valid
a pixel depth, causing the resetting to fail. A particular example is X11 on
IRIX, when only 16bit output modes work. Initially SDL tells us that the pixel
depth is 32bit. Trying to set this up causes a crash though.

Since there is no way to validate SDL's return value, we simply limit the reset
to platforms where it is actually required, i.e. Win32.
This commit is contained in:
Johannes Schickel 2016-02-17 16:17:39 +01:00
parent 4145109937
commit fd688b73d7
2 changed files with 24 additions and 7 deletions

View file

@ -127,7 +127,8 @@ SurfaceSdlGraphicsManager::SurfaceSdlGraphicsManager(SdlEventSource *sdlEventSou
#if SDL_VERSION_ATLEAST(2, 0, 0)
_renderer(nullptr), _screenTexture(nullptr),
_viewport(), _windowWidth(1), _windowHeight(1),
#else
#endif
#if defined(WIN32) && !SDL_VERSION_ATLEAST(2, 0, 0)
_originalBitsPerPixel(0),
#endif
_screen(0), _tmpscreen(0),
@ -801,8 +802,9 @@ bool SurfaceSdlGraphicsManager::loadGFXMode() {
} else
#endif
{
// Save the original bpp to be able to restore the video mode on unload
#if !SDL_VERSION_ATLEAST(2, 0, 0)
#if defined(WIN32) && !SDL_VERSION_ATLEAST(2, 0, 0)
// Save the original bpp to be able to restore the video mode on
// unload. See _originalBitsPerPixel documentation.
if (_originalBitsPerPixel == 0) {
const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo();
_originalBitsPerPixel = videoInfo->vfmt->BitsPerPixel;
@ -947,9 +949,10 @@ void SurfaceSdlGraphicsManager::unloadGFXMode() {
#endif
DestroyScalers();
#if !SDL_VERSION_ATLEAST(2, 0, 0)
// Reset video mode to original
// This will ensure that any new graphic manager will use the initial BPP when listing available modes
#if defined(WIN32) && !SDL_VERSION_ATLEAST(2, 0, 0)
// Reset video mode to original.
// This will ensure that any new graphic manager will use the initial BPP
// when listing available modes. See _originalBitsPerPixel documentation.
if (_originalBitsPerPixel != 0)
SDL_SetVideoMode(_videoMode.screenWidth, _videoMode.screenHeight, _originalBitsPerPixel, _videoMode.fullscreen ? (SDL_FULLSCREEN | SDL_SWSURFACE) : SDL_SWSURFACE);
#endif

View file

@ -251,8 +251,22 @@ protected:
};
VideoState _videoMode, _oldVideoMode;
// Original BPP to restore the video mode on unload
#if defined(WIN32) && !SDL_VERSION_ATLEAST(2, 0, 0)
/**
* Original BPP to restore the video mode on unload.
*
* This is required to make listing video modes for the OpenGL output work
* on Windows 8+. On these systems OpenGL modes are only available for
* 32bit formats. However, we setup a 16bit format and thus mode listings
* for OpenGL will return an empty list afterwards.
*
* In theory we might require this behavior on non-Win32 platforms too.
* However, SDL sometimes gives us invalid pixel formats for X11 outputs
* causing crashes when trying to setup the original pixel format.
* See bug #7038 "IRIX: X BadMatch when trying to start any 640x480 game".
*/
uint8 _originalBitsPerPixel;
#endif
/** Force full redraw on next updateScreen */
bool _forceFull;