From 5d05acbf1faf31d48a6fbcc784af3cb9c7a41522 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 26 Feb 2021 13:11:44 +0100 Subject: [PATCH] Platform: explicitly destroy GL::Context before the GL context. So in case it touches the GL state in some way, it doesn't do that on an already destroyed context. The windowless apps do this all implicitly due to the WindowlessGLContext encapsulation. --- src/Magnum/Platform/AbstractXApplication.cpp | 2 ++ src/Magnum/Platform/AndroidApplication.cpp | 4 ++++ src/Magnum/Platform/EmscriptenApplication.cpp | 2 ++ src/Magnum/Platform/GlfwApplication.cpp | 6 ++++++ src/Magnum/Platform/Sdl2Application.cpp | 2 ++ 5 files changed, 16 insertions(+) diff --git a/src/Magnum/Platform/AbstractXApplication.cpp b/src/Magnum/Platform/AbstractXApplication.cpp index 99f34a05d..6a98a0ee6 100644 --- a/src/Magnum/Platform/AbstractXApplication.cpp +++ b/src/Magnum/Platform/AbstractXApplication.cpp @@ -109,6 +109,8 @@ bool AbstractXApplication::tryCreate(const Configuration& configuration, const G } AbstractXApplication::~AbstractXApplication() { + /* Destroy Magnum context first to avoid it potentially accessing the + now-destroyed GL context after */ _context.reset(); /* Shut down context handler */ diff --git a/src/Magnum/Platform/AndroidApplication.cpp b/src/Magnum/Platform/AndroidApplication.cpp index b45ea7d77..e078c323f 100644 --- a/src/Magnum/Platform/AndroidApplication.cpp +++ b/src/Magnum/Platform/AndroidApplication.cpp @@ -77,6 +77,10 @@ AndroidApplication::AndroidApplication(const Arguments& arguments, NoCreateT): _ } AndroidApplication::~AndroidApplication() { + /* Destroy Magnum context first to avoid it potentially accessing the + now-destroyed GL context after */ + _context.reset(); + eglMakeCurrent(_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); eglDestroyContext(_display, _glContext); eglDestroySurface(_display, _surface); diff --git a/src/Magnum/Platform/EmscriptenApplication.cpp b/src/Magnum/Platform/EmscriptenApplication.cpp index 86d826c6c..f8574e4a0 100644 --- a/src/Magnum/Platform/EmscriptenApplication.cpp +++ b/src/Magnum/Platform/EmscriptenApplication.cpp @@ -260,6 +260,8 @@ EmscriptenApplication::EmscriptenApplication(const Arguments& arguments, NoCreat EmscriptenApplication::~EmscriptenApplication() { #ifdef MAGNUM_TARGET_GL + /* Destroy Magnum context first to avoid it potentially accessing the + now-destroyed GL context after */ _context.reset(); emscripten_webgl_destroy_context(_glContext); diff --git a/src/Magnum/Platform/GlfwApplication.cpp b/src/Magnum/Platform/GlfwApplication.cpp index 986413a6b..32d0d68f4 100644 --- a/src/Magnum/Platform/GlfwApplication.cpp +++ b/src/Magnum/Platform/GlfwApplication.cpp @@ -668,6 +668,12 @@ void GlfwApplication::setupCallbacks() { } GlfwApplication::~GlfwApplication() { + #ifdef MAGNUM_TARGET_GL + /* Destroy Magnum context first to avoid it potentially accessing the + now-destroyed GL context after */ + _context.reset(); + #endif + glfwDestroyWindow(_window); for(auto& cursor: _cursors) glfwDestroyCursor(cursor); diff --git a/src/Magnum/Platform/Sdl2Application.cpp b/src/Magnum/Platform/Sdl2Application.cpp index c0770d5cd..28f7c2d40 100644 --- a/src/Magnum/Platform/Sdl2Application.cpp +++ b/src/Magnum/Platform/Sdl2Application.cpp @@ -796,6 +796,8 @@ Sdl2Application::~Sdl2Application() { all. */ #ifdef MAGNUM_TARGET_GL + /* Destroy Magnum context first to avoid it potentially accessing the + now-destroyed GL context after */ _context.reset(); #ifndef CORRADE_TARGET_EMSCRIPTEN