diff --git a/doc/changelog.dox b/doc/changelog.dox index bb2c60129..eef409ed1 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -87,6 +87,13 @@ See also: - Fixed compilation of the @ref GL library on macOS with ANGLE --- new code assumed macOS is always desktop GL (see [mosra/magnum#452](https://github.com/mosra/magnum/issues/452)) +@subsection changelog-latest-bugfixes Bug fixes + +- Creating @ref Platform::WindowlessEglApplication again after it was + destroyed could fail with an error saying "cannot make the previous context + current" on certain system. This was due to EGL not destroying the context + if it's still made current. + @subsection changelog-latest-compatibility Potential compatibility breakages, removed APIs - Removed remaining APIs deprecated in version 2018.10, in particular: diff --git a/src/Magnum/Platform/WindowlessEglApplication.cpp b/src/Magnum/Platform/WindowlessEglApplication.cpp index b514e2b06..9aaad65ee 100644 --- a/src/Magnum/Platform/WindowlessEglApplication.cpp +++ b/src/Magnum/Platform/WindowlessEglApplication.cpp @@ -442,7 +442,19 @@ WindowlessEglContext::WindowlessEglContext(WindowlessEglContext&& other): } WindowlessEglContext::~WindowlessEglContext() { - if(_context) eglDestroyContext(_display, _context); + if(_context) { + /* eglDestroyContext() doesn't actually destroy the context if it's + still current, it's only destroyed once eglMakeCurrent() makes some + other context current. This causes the "cannot make the previous + context current" error from above to appear if one creates an EGL + context again for a second time --- we switch from the (now zombie) + context to a new one to read the vendor string for the + "no-forward-compatible-core-context" workaround, at which point the + zombie gets finally killed, which then means we can't + eglMakeCurrent() it back after. */ + eglMakeCurrent(_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + eglDestroyContext(_display, _context); + } #if defined(MAGNUM_TARGET_GLES) && !defined(MAGNUM_TARGET_WEBGL) if(_surface) eglDestroySurface(_display, _surface); #endif