Shutting down and reinitializing EGL context does not seem to work

Running with ubuntu 16.04 with 418.87, I have an EGL/OpenGL app that works really well as long as I don’t try to re-initialize the EGL context. Doing so results in an out of memory error, whenever I try to allocate a framebuffer or other GPU buffer.

I have created a very simple example, that ends in a segmentation fault after the second iteration.
It’s likely I may not be shutting down correctly, but it’s becoming important for me to be able to initialize and re-initialize rendering context, without having to shutdown the process.

Thank you in advance. Overly verbose code attached.
eglinit.cpp (12.3 KB)

Any news/ideas on this? Still present on 18.04 and 440.33

Interesting. At first I thought this problem was related to the fact that your app calls eglDestroyContext and eglTerminate while the context is still current, but even if I fix this line to properly lose current, the problem still occurs:


The problem instead seems to be related to the fact that eglGetDisplay(EGL_DEFAULT_DISPLAY) implicitly connects to the X server if the $DISPLAY environment variable is set, which doesn’t seem to properly survive an eglTerminate / eglInitialize transition. I filed internal NVIDIA bug 2806644 to track down what’s going on here.

If you don’t actually want to use X11, then I would recommend using eglGetPlatformDisplay with the EGLDevice extensions to explicitly choose a device without a window system. Here are some links to the relevant extensions:

Thank you very much for looking into this, Aaron.

To clarify, you mean line 90 in the code I posted: eglDpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); is still grabbing the x11 display?

I believe the block marked with //target a specific GPU already does avoid binding to x11. After changing the code to:


as you suggested, this code path runs through all 20 iterations without crashes.

If the X11 path could be fixed as well it would be immensely helpful…

Thank you again.

Yes, on platforms with a single window system such as Android or Windows, eglGetDisplay(EGL_DEFAULT_DISPLAY) is not a problem. But on an operating system that might have multiple window systems running simultaneously, it’s ambiguous. So the driver does its best to guess what your application wants based on the environment, including trying X11 or Wayland when available.

eglGetPlatformDisplay was added to avoid making the driver guess what the application wants.

I’ll need to confirm this with a simpler example, but even in the case where EGL can be shutdown and reinitialized (ie when not using X11), using openGL after the 2nd EGL initialization reports an OGL out of memory error. I’ll see if I can reproduce it in a new version of eglInit.cpp
I’m not sure if this is part of the same bug or not…