From a21636fee80cde98f6fd43d997d08304ce8b11dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 29 Apr 2023 13:04:33 +0200 Subject: [PATCH] Platform: disallow WindowFlag::Contextless when creating a GL context. Used to be silently ignored in some places, silently discarded in some other and probably causing an error elsewhere. Better be strict instead. --- src/Magnum/Platform/EmscriptenApplication.cpp | 5 ++++- src/Magnum/Platform/EmscriptenApplication.h | 5 ++++- src/Magnum/Platform/GlfwApplication.cpp | 5 ++++- src/Magnum/Platform/GlfwApplication.h | 5 ++++- src/Magnum/Platform/Sdl2Application.cpp | 7 +++++-- src/Magnum/Platform/Sdl2Application.h | 5 ++++- 6 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/Magnum/Platform/EmscriptenApplication.cpp b/src/Magnum/Platform/EmscriptenApplication.cpp index adb3c504c..fcf46b306 100644 --- a/src/Magnum/Platform/EmscriptenApplication.cpp +++ b/src/Magnum/Platform/EmscriptenApplication.cpp @@ -343,7 +343,10 @@ bool EmscriptenApplication::tryCreate(const Configuration& configuration) { #ifdef MAGNUM_TARGET_GL bool EmscriptenApplication::tryCreate(const Configuration& configuration, const GLConfiguration& glConfiguration) { - CORRADE_ASSERT(_context->version() == GL::Version::None, "Platform::EmscriptenApplication::tryCreate(): window with OpenGL context already created", false); + CORRADE_ASSERT(!(configuration.windowFlags() & Configuration::WindowFlag::Contextless), + "Platform::EmscriptenApplication::tryCreate(): cannot pass Configuration::WindowFlag::Contextless when creating an OpenGL context", false); + CORRADE_ASSERT(_context->version() == GL::Version::None, + "Platform::EmscriptenApplication::tryCreate(): window with OpenGL context already created", false); /* Create emscripten WebGL context */ EmscriptenWebGLContextAttributes attrs; diff --git a/src/Magnum/Platform/EmscriptenApplication.h b/src/Magnum/Platform/EmscriptenApplication.h index 7f41f8242..15710aa2c 100644 --- a/src/Magnum/Platform/EmscriptenApplication.h +++ b/src/Magnum/Platform/EmscriptenApplication.h @@ -1216,7 +1216,10 @@ class EmscriptenApplication::Configuration { * @ref EmscriptenApplication(const Arguments&, const Configuration&), * @ref create(const Configuration&) or * @ref tryCreate(const Configuration&) to prevent implicit - * creation of an WebGL context. + * creation of an WebGL context. Can't be used with + * @ref EmscriptenApplication(const Arguments&, const Configuration&, const GLConfiguration&), + * @ref create(const Configuration&, const GLConfiguration&) or + * @ref tryCreate(const Configuration&, const GLConfiguration&). */ Contextless = 1 << 0, diff --git a/src/Magnum/Platform/GlfwApplication.cpp b/src/Magnum/Platform/GlfwApplication.cpp index 45fd61e51..4ac3188ed 100644 --- a/src/Magnum/Platform/GlfwApplication.cpp +++ b/src/Magnum/Platform/GlfwApplication.cpp @@ -409,7 +409,10 @@ GlfwApplication::InputEvent::Modifiers currentGlfwModifiers(GLFWwindow* window) #ifdef MAGNUM_TARGET_GL bool GlfwApplication::tryCreate(const Configuration& configuration, const GLConfiguration& glConfiguration) { - CORRADE_ASSERT(!_window && _context->version() == GL::Version::None, "Platform::GlfwApplication::tryCreate(): window with OpenGL context already created", false); + CORRADE_ASSERT(!(configuration.windowFlags() & Configuration::WindowFlag::Contextless), + "Platform::GlfwApplication::tryCreate(): cannot pass Configuration::WindowFlag::Contextless when creating an OpenGL context", false); + CORRADE_ASSERT(!_window && _context->version() == GL::Version::None, + "Platform::GlfwApplication::tryCreate(): window with OpenGL context already created", false); /* Save DPI scaling values from configuration for future use, scale window based on those */ diff --git a/src/Magnum/Platform/GlfwApplication.h b/src/Magnum/Platform/GlfwApplication.h index 70519d035..e2e42cf74 100644 --- a/src/Magnum/Platform/GlfwApplication.h +++ b/src/Magnum/Platform/GlfwApplication.h @@ -1113,7 +1113,10 @@ class GlfwApplication::Configuration { * @ref GlfwApplication(const Arguments&, const Configuration&), * @ref create(const Configuration&) or * @ref tryCreate(const Configuration&) to prevent implicit - * creation of an OpenGL context. + * creation of an OpenGL context. Can't be used with + * @ref GlfwApplication(const Arguments&, const Configuration&, const GLConfiguration&), + * @ref create(const Configuration&, const GLConfiguration&) or + * @ref tryCreate(const Configuration&, const GLConfiguration&). * * @note Supported since GLFW 3.2. */ diff --git a/src/Magnum/Platform/Sdl2Application.cpp b/src/Magnum/Platform/Sdl2Application.cpp index f2224a068..834b8c837 100644 --- a/src/Magnum/Platform/Sdl2Application.cpp +++ b/src/Magnum/Platform/Sdl2Application.cpp @@ -470,7 +470,10 @@ bool Sdl2Application::tryCreate(const Configuration& configuration) { #ifdef MAGNUM_TARGET_GL bool Sdl2Application::tryCreate(const Configuration& configuration, const GLConfiguration& glConfiguration) { - CORRADE_ASSERT(_context->version() == GL::Version::None, "Platform::Sdl2Application::tryCreate(): context already created", false); + CORRADE_ASSERT(!(configuration.windowFlags() & Configuration::WindowFlag::Contextless), + "Platform::Sdl2Application::tryCreate(): cannot pass Configuration::WindowFlag::Contextless when creating an OpenGL context", false); + CORRADE_ASSERT(_context->version() == GL::Version::None, + "Platform::Sdl2Application::tryCreate(): context already created", false); /* Enable double buffering, set up buffer sizes */ SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); @@ -621,7 +624,7 @@ bool Sdl2Application::tryCreate(const Configuration& configuration, const GLConf if(!(_window = SDL_CreateWindow(configuration.title().data(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, scaledWindowSize.x(), scaledWindowSize.y(), - SDL_WINDOW_OPENGL|SDL_WINDOW_HIDDEN|SDL_WINDOW_ALLOW_HIGHDPI|Uint32(configuration.windowFlags()&~Configuration::WindowFlag::Contextless)))) + SDL_WINDOW_OPENGL|SDL_WINDOW_HIDDEN|SDL_WINDOW_ALLOW_HIGHDPI|Uint32(configuration.windowFlags())))) { Error() << "Platform::Sdl2Application::tryCreate(): cannot create window:" << SDL_GetError(); return false; diff --git a/src/Magnum/Platform/Sdl2Application.h b/src/Magnum/Platform/Sdl2Application.h index fd2c6ac5a..8d2648ce3 100644 --- a/src/Magnum/Platform/Sdl2Application.h +++ b/src/Magnum/Platform/Sdl2Application.h @@ -1726,7 +1726,10 @@ class Sdl2Application::Configuration { * @ref Sdl2Application(const Arguments&, const Configuration&), * @ref create(const Configuration&) or * @ref tryCreate(const Configuration&) to prevent implicit - * creation of an OpenGL context. + * creation of an OpenGL context. Can't be used with + * @ref Sdl2Application(const Arguments&, const Configuration&, const GLConfiguration&), + * @ref create(const Configuration&, const GLConfiguration&) or + * @ref tryCreate(const Configuration&, const GLConfiguration&). */ Contextless = 1u << 31, /* Hope this won't ever conflict with anything */