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