diff --git a/src/Platform/AbstractXApplication.cpp b/src/Platform/AbstractXApplication.cpp index 84bbf4e6c..c6c846bcd 100644 --- a/src/Platform/AbstractXApplication.cpp +++ b/src/Platform/AbstractXApplication.cpp @@ -51,7 +51,11 @@ AbstractXApplication::AbstractXApplication(Implementation::AbstractContextHandle AbstractXApplication::AbstractXApplication(Implementation::AbstractContextHandler* contextHandler, const Arguments&, std::nullptr_t): contextHandler(contextHandler), c(nullptr), flags(Flag::Redraw) {} void AbstractXApplication::createContext(const Configuration& configuration) { - CORRADE_ASSERT(!c, "AbstractXApplication::createContext(): context already created", ); + if(!tryCreateContext(configuration)) std::exit(1); +} + +bool AbstractXApplication::tryCreateContext(const Configuration& configuration) { + CORRADE_ASSERT(!c, "AbstractXApplication::tryCreateContext(): context already created", ); viewportSize = configuration.size(); @@ -67,8 +71,8 @@ void AbstractXApplication::createContext(const Configuration& configuration) { visTemplate.visualid = visualId; visInfo = XGetVisualInfo(display, VisualIDMask, &visTemplate, &visualCount); if(!visInfo) { - Error() << "Cannot get X visual"; - std::exit(1); + Error() << "Platform::WindowlessGlxApplication::tryCreateContext(): cannot get X visual"; + return false; } /* Create X Window */ @@ -97,6 +101,7 @@ void AbstractXApplication::createContext(const Configuration& configuration) { contextHandler->makeCurrent(); c = new Context; + return true; } AbstractXApplication::~AbstractXApplication() { diff --git a/src/Platform/AbstractXApplication.h b/src/Platform/AbstractXApplication.h index 12affaaa9..ab10cea23 100644 --- a/src/Platform/AbstractXApplication.h +++ b/src/Platform/AbstractXApplication.h @@ -90,6 +90,9 @@ class AbstractXApplication { /** @copydoc Sdl2Application::createContext() */ void createContext(const Configuration& configuration); + /** @copydoc Sdl2Application::tryCreateContext() */ + bool tryCreateContext(const Configuration& configuration); + /** @{ @name Drawing functions */ /** @copydoc Sdl2Application::viewportEvent() */ diff --git a/src/Platform/GlutApplication.cpp b/src/Platform/GlutApplication.cpp index 661e360c2..394546f98 100644 --- a/src/Platform/GlutApplication.cpp +++ b/src/Platform/GlutApplication.cpp @@ -60,10 +60,7 @@ void GlutApplication::initialize(int& argc, char** argv) { } void GlutApplication::createContext(const Configuration& configuration) { - if(!tryCreateContext(configuration)) { - Error() << "Platform::GlutApplication::createContext(): cannot create context"; - std::exit(1); - } + if(!tryCreateContext(configuration)) std::exit(1); } bool GlutApplication::tryCreateContext(const Configuration& configuration) { @@ -76,8 +73,10 @@ bool GlutApplication::tryCreateContext(const Configuration& configuration) { glutInitDisplayMode(flags); glutInitWindowSize(configuration.size().x(), configuration.size().y()); - if(!glutCreateWindow(configuration.title().data())) + if(!glutCreateWindow(configuration.title().data())) { + Error() << "Platform::GlutApplication::tryCreateContext(): cannot create context"; return false; + } glutReshapeFunc(staticViewportEvent); glutSpecialFunc(staticKeyEvent); glutMouseFunc(staticMouseEvent); diff --git a/src/Platform/NaClApplication.cpp b/src/Platform/NaClApplication.cpp index 1094316f8..3b6648ba2 100644 --- a/src/Platform/NaClApplication.cpp +++ b/src/Platform/NaClApplication.cpp @@ -69,10 +69,7 @@ NaClApplication::NaClApplication(const Arguments& arguments, std::nullptr_t): In } void NaClApplication::createContext(const Configuration& configuration) { - if(!tryCreateContext(configuration)) { - Error() << "Platform::NaClApplication::createContext(): cannot create context"; - std::exit(1); - } + if(!tryCreateContext(configuration)) std::exit(1); } bool NaClApplication::tryCreateContext(const Configuration& configuration) { @@ -93,13 +90,16 @@ bool NaClApplication::tryCreateContext(const Configuration& configuration) { graphics = new pp::Graphics3D(this, attributes); if(graphics->is_null()) { + Error() << "Platform::NaClApplication::tryCreateContext(): cannot create context"; delete graphics; graphics = nullptr; return false; } if(!BindGraphics(*graphics)) { Error() << "Platform::NaClApplication::tryCreateContext(): cannot bind graphics"; - std::exit(1); + delete graphics; + graphics = nullptr; + return false; } fullscreen = new pp::Fullscreen(this); diff --git a/src/Platform/Sdl2Application.cpp b/src/Platform/Sdl2Application.cpp index 9d791e729..4377aaca5 100644 --- a/src/Platform/Sdl2Application.cpp +++ b/src/Platform/Sdl2Application.cpp @@ -89,10 +89,7 @@ void Sdl2Application::initialize() { } void Sdl2Application::createContext(const Configuration& configuration) { - if(!tryCreateContext(configuration)) { - Error() << "Platform::Sdl2Application::createContext(): cannot create context:" << SDL_GetError(); - std::exit(1); - } + if(!tryCreateContext(configuration)) std::exit(1); } bool Sdl2Application::tryCreateContext(const Configuration& configuration) { @@ -115,10 +112,13 @@ bool Sdl2Application::tryCreateContext(const Configuration& configuration) { if(!(window = SDL_CreateWindow(configuration.title().data(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, configuration.size().x(), configuration.size().y(), - SDL_WINDOW_OPENGL|flags))) + SDL_WINDOW_OPENGL|flags))) { + Error() << "Platform::Sdl2Application::tryCreateContext(): cannot create window:" << SDL_GetError(); return false; + } if(!(context = SDL_GL_CreateContext(window))) { + Error() << "Platform::Sdl2Application::tryCreateContext(): cannot create context:" << SDL_GetError(); SDL_DestroyWindow(window); window = nullptr; return false; diff --git a/src/Platform/WindowlessGlxApplication.cpp b/src/Platform/WindowlessGlxApplication.cpp index 5feedb01f..1940e704f 100644 --- a/src/Platform/WindowlessGlxApplication.cpp +++ b/src/Platform/WindowlessGlxApplication.cpp @@ -47,8 +47,12 @@ WindowlessGlxApplication::WindowlessGlxApplication(const Arguments&): c(nullptr) WindowlessGlxApplication::WindowlessGlxApplication(const Arguments&, std::nullptr_t): c(nullptr) {} -void WindowlessGlxApplication::createContext(const Configuration&) { - CORRADE_ASSERT(!c, "WindowlessGlxApplication::createContext(): context already created", ); +void WindowlessGlxApplication::createContext(const Configuration& configuration) { + if(!tryCreateContext(configuration)) std::exit(1); +} + +bool WindowlessGlxApplication::tryCreateContext(const Configuration&) { + CORRADE_ASSERT(!c, "Platform::WindowlessGlxApplication::tryCreateContext(): context already created", ); display = XOpenDisplay(nullptr); @@ -56,8 +60,8 @@ void WindowlessGlxApplication::createContext(const Configuration&) { int major, minor; glXQueryVersion(display, &major, &minor); if(major == 1 && minor < 4) { - Error() << "WindowlessGlxApplication: GLX version 1.4 or greater is required."; - std::exit(1); + Error() << "Platform::WindowlessGlxApplication::tryCreateContext(): GLX version 1.4 or greater is required"; + return false; } /* Choose config */ @@ -65,8 +69,8 @@ void WindowlessGlxApplication::createContext(const Configuration&) { static const int fbAttributes[] = { None }; GLXFBConfig* configs = glXChooseFBConfig(display, DefaultScreen(display), fbAttributes, &configCount); if(!configCount) { - Error() << "WindowlessGlxApplication: no supported framebuffer configuration found."; - std::exit(1); + Error() << "Platform::WindowlessGlxApplication::tryCreateContext(): no supported framebuffer configuration found"; + return false; } GLint contextAttributes[] = { @@ -82,8 +86,8 @@ void WindowlessGlxApplication::createContext(const Configuration&) { PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC) glXGetProcAddress((const GLubyte*)"glXCreateContextAttribsARB"); context = glXCreateContextAttribsARB(display, configs[0], nullptr, True, contextAttributes); if(!context) { - Error() << "WindowlessGlxApplication: cannot create context."; - std::exit(1); + Error() << "Platform::WindowlessGlxApplication::tryCreateContext(): cannot create context"; + return false; } /* Create pbuffer */ @@ -98,11 +102,12 @@ void WindowlessGlxApplication::createContext(const Configuration&) { /* Set OpenGL context as current */ if(!glXMakeContextCurrent(display, pbuffer, pbuffer, context)) { - Error() << "WindowlessGlxApplication: cannot make context current"; - std::exit(1); + Error() << "Platform::WindowlessGlxApplication::tryCreateContext(): cannot make context current"; + return false; } c = new Context; + return true; } WindowlessGlxApplication::~WindowlessGlxApplication() { diff --git a/src/Platform/WindowlessGlxApplication.h b/src/Platform/WindowlessGlxApplication.h index 921721f27..937d7b3fb 100644 --- a/src/Platform/WindowlessGlxApplication.h +++ b/src/Platform/WindowlessGlxApplication.h @@ -109,6 +109,9 @@ class WindowlessGlxApplication { /** @copydoc Sdl2Application::createContext() */ void createContext(const Configuration& configuration); + /** @copydoc Sdl2Application::tryCreateContext() */ + bool tryCreateContext(const Configuration& configuration); + private: Display* display; GLXContext context; diff --git a/src/Platform/WindowlessNaClApplication.cpp b/src/Platform/WindowlessNaClApplication.cpp index e0065b82c..f28e27e67 100644 --- a/src/Platform/WindowlessNaClApplication.cpp +++ b/src/Platform/WindowlessNaClApplication.cpp @@ -68,10 +68,7 @@ WindowlessNaClApplication::WindowlessNaClApplication(const Arguments& arguments, } void WindowlessNaClApplication::createContext(const Configuration& configuration) { - if(!tryCreateContext(configuration)) { - Error() << "Platform::WindowlessNaClApplication::createContext(): cannot create context"; - std::exit(1); - } + if(!tryCreateContext(configuration)) std::exit(1); } bool WindowlessNaClApplication::tryCreateContext(const Configuration&) { @@ -88,13 +85,16 @@ bool WindowlessNaClApplication::tryCreateContext(const Configuration&) { graphics = new pp::Graphics3D(this, attributes); if(graphics->is_null()) { + Error() << "Platform::WindowlessNaClApplication::tryCreateContext(): cannot create context"; delete graphics; graphics = nullptr; return false; } if(!BindGraphics(*graphics)) { Error() << "Platform::WindowlessNaClApplication::tryCreateContext(): cannot bind graphics"; - std::exit(1); + delete graphics; + graphics = nullptr; + return false; } glSetCurrentContextPPAPI(graphics->pp_resource());