From 7407bbdac9dd8e354fc6626b826e4f4de69c7500 Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 12 Jun 2015 01:08:58 +0200 Subject: [PATCH] Add a function for SDL error handling --- apps/openmw/engine.cpp | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index aa00f5e9c..01ecd3d11 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -55,6 +55,15 @@ #include "mwstate/statemanagerimp.hpp" +namespace +{ + void checkSDLError(int ret) + { + if (ret != 0) + std::cerr << "SDL error: " << SDL_GetError() << std::endl; + } +} + void OMW::Engine::executeLocalScripts() { MWWorld::LocalScripts& localScripts = MWBase::Environment::get().getWorld()->getLocalScripts(); @@ -342,18 +351,16 @@ void OMW::Engine::createWindow(Settings::Manager& settings) SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, settings.getBool("minimize on focus loss", "Video") ? "1" : "0"); - SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0); - SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); + checkSDLError(SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8)); + checkSDLError(SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8)); + checkSDLError(SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8)); + checkSDLError(SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0)); + checkSDLError(SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24)); if (antialiasing > 0) { - if (SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1) != 0) - std::cerr << "SDL error: " << SDL_GetError() << std::endl; - if (SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, antialiasing) != 0) - std::cerr << "SDL error: " << SDL_GetError() << std::endl; + checkSDLError(SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1)); + checkSDLError(SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, antialiasing)); } while (!mWindow) @@ -367,8 +374,7 @@ void OMW::Engine::createWindow(Settings::Manager& settings) std::cout << "Note: " << antialiasing << "x antialiasing not supported, trying " << antialiasing/2 << std::endl; antialiasing /= 2; Settings::Manager::setInt("antialiasing", "Video", antialiasing); - if (SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, antialiasing) != 0) - std::cerr << "SDL error: " << SDL_GetError() << std::endl; + checkSDLError(SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, antialiasing)); continue; } else