Browse Source

EGLDisplay non-terminating when mixing WindowlessEGLApplication & shared contexts

pull/437/head
aspioupiou 6 years ago
parent
commit
a91c68601f
  1. 16
      src/Magnum/Platform/WindowlessEglApplication.cpp
  2. 3
      src/Magnum/Platform/WindowlessEglApplication.h

16
src/Magnum/Platform/WindowlessEglApplication.cpp

@ -83,6 +83,8 @@ bool extensionSupported(const char* const extensions, Containers::ArrayView<cons
WindowlessEglContext::WindowlessEglContext(const Configuration& configuration, GLContext* const magnumContext) {
#ifndef MAGNUM_TARGET_WEBGL
/* If relevant extensions are supported, try to find some display using
those APIs, as that works reliably also when running headless. This
would ideally use EGL 1.5 APIs but since we still want to support
@ -273,6 +275,8 @@ WindowlessEglContext::WindowlessEglContext(const Configuration& configuration, G
}
#endif
if(configuration.sharedContext() != EGL_NO_CONTEXT) _sharedContext = true;
if(!(_context = eglCreateContext(_display, config,
#ifndef MAGNUM_TARGET_WEBGL
configuration.sharedContext(),
@ -309,7 +313,17 @@ WindowlessEglContext::~WindowlessEglContext() {
#if defined(MAGNUM_TARGET_GLES) && !defined(MAGNUM_TARGET_WEBGL)
if(_surface) eglDestroySurface(_display, _surface);
#endif
if(_display) eglTerminate(_display);
/**
* From Khronos, `Multiple calls made to eglGetPlatformDisplayEXT with the same <platform>
* and <native_display> will return the same EGLDisplay handle.` This makes a problem when
* the context is shared with another one, because both shares the same EGLDisplay.
* To avoid errors when trying to make current the other context (EGL_NOT_INITIALIZED)
* we don't terminate the shared display.
* It is then the user's responsaibility to first kill the shared EGL instance
* (which won't terminate the display), and then main one, killing everything.
*/
if(_sharedContext && _display) eglTerminate(_display);
}
WindowlessEglContext& WindowlessEglContext::operator=(WindowlessEglContext && other) {

3
src/Magnum/Platform/WindowlessEglApplication.h

@ -132,6 +132,9 @@ class WindowlessEglContext {
EGLContext glContext() { return _context; }
private:
/* Stores whether the EGL context is shared or not */
bool _sharedContext = false;
EGLDisplay _display{};
EGLContext _context{};
#if defined(MAGNUM_TARGET_GLES) && !defined(MAGNUM_TARGET_WEBGL)

Loading…
Cancel
Save