[Scummvm-git-logs] scummvm master -> 5412533decd9e559487289c56f2bd45a5342f179

criezy criezy at scummvm.org
Mon Feb 8 12:59:56 UTC 2021


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
5412533dec SDL: Fix trying to set unsupported pixel format when changing  gfx mode


Commit: 5412533decd9e559487289c56f2bd45a5342f179
    https://github.com/scummvm/scummvm/commit/5412533decd9e559487289c56f2bd45a5342f179
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2021-02-08T12:59:52Z

Commit Message:
SDL: Fix trying to set unsupported pixel format when changing  gfx mode

When switching between the SDL and OpenGL graphics managers, trying
to restore the state could fail as the two managers do not have the
same list of supported formats, so we may not be able to transfer
the pixel format from one to the other. This then resulted in an
assert.

This fixes bug #12079

Changed paths:
    backends/graphics/sdl/sdl-graphics.cpp
    backends/platform/sdl/sdl.cpp


diff --git a/backends/graphics/sdl/sdl-graphics.cpp b/backends/graphics/sdl/sdl-graphics.cpp
index 710e942657..9074b33f5f 100644
--- a/backends/graphics/sdl/sdl-graphics.cpp
+++ b/backends/graphics/sdl/sdl-graphics.cpp
@@ -77,7 +77,15 @@ SdlGraphicsManager::State SdlGraphicsManager::getState() const {
 bool SdlGraphicsManager::setState(const State &state) {
 	beginGFXTransaction();
 #ifdef USE_RGB_COLOR
-		initSize(state.screenWidth, state.screenHeight, &state.pixelFormat);
+		// When switching between the SDL and OpenGL graphics manager, the list
+		// of supported format changes. This means that the pixel format in the
+		// state may not be supported. In that case use the preferred supported
+		// pixel format instead.
+		Graphics::PixelFormat format = state.pixelFormat;
+		Common::List<Graphics::PixelFormat> supportedFormats = getSupportedFormats();
+		if (Common::find(supportedFormats.begin(), supportedFormats.end(), format) == supportedFormats.end())
+			format = supportedFormats.front();
+		initSize(state.screenWidth, state.screenHeight, &format);
 #else
 		initSize(state.screenWidth, state.screenHeight, nullptr);
 #endif
diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
index 31d87bf423..782e877e28 100644
--- a/backends/platform/sdl/sdl.cpp
+++ b/backends/platform/sdl/sdl.cpp
@@ -789,14 +789,25 @@ bool OSystem_SDL::setGraphicsMode(int mode, uint flags) {
 	_graphicsMode = mode;
 
 	if (switchedManager) {
-		if (sdlGraphicsManager) {
+		if (sdlGraphicsManager)
 			sdlGraphicsManager->activateManager();
+		else if (sdlGraphics3dManager)
+			sdlGraphics3dManager->activateManager();
+
+		// Setup the graphics mode and size first
+		// This is needed so that we can check the supported pixel formats when
+		// restoring the state.
+		_graphicsManager->beginGFXTransaction();
+		if (!_graphicsManager->setGraphicsMode(_graphicsModeIds[mode], flags))
+			return false;
+		_graphicsManager->initSize(_gfxManagerState.screenWidth, _gfxManagerState.screenHeight);
+		_graphicsManager->endGFXTransaction();
+
+		// Restore state
+		if (sdlGraphicsManager) {
 			// This failing will probably have bad consequences...
-			if (!sdlGraphicsManager->setState(_gfxManagerState)) {
+			if (!sdlGraphicsManager->setState(_gfxManagerState))
 				return false;
-			}
-		} else if (sdlGraphics3dManager) {
-			sdlGraphics3dManager->activateManager();
 		}
 
 		// Next setup the cursor again
@@ -810,8 +821,7 @@ bool OSystem_SDL::setGraphicsMode(int mode, uint flags) {
 		}
 
 		_graphicsManager->beginGFXTransaction();
-		// Oh my god if this failed the client code might just explode.
-		return _graphicsManager->setGraphicsMode(_graphicsModeIds[mode], flags);
+		return true;
 	} else {
 		return _graphicsManager->setGraphicsMode(_graphicsModeIds[mode], flags);
 	}




More information about the Scummvm-git-logs mailing list