MonoGame/MonoGame · error · Exception
Could not terminate EGL connection
Error message
Could not terminate EGL connection
What it means
Thrown by MonoGameAndroidGameView.DestroyGLContext when egl.EglTerminate(eglDisplay) returns false, meaning the EGL connection could not be terminated. The message is appended with GetErrorAsString() for the EGL error code. This occurs during the second phase of context teardown (after the context itself), when terminating the EGL display connection fails.
Source
Thrown at MonoGame.Framework/Platform/Android/MonoGameAndroidGameView.cs:766
protected void EnsureUndisposed()
{
if (disposed)
throw new ObjectDisposedException("");
}
protected void DestroyGLContext()
{
if (eglContext != null)
{
if (!egl.EglDestroyContext(eglDisplay, eglContext))
throw new Exception("Could not destroy EGL context" + GetErrorAsString());
eglContext = null;
}
if (eglDisplay != null)
{
if (!egl.EglTerminate(eglDisplay))
throw new Exception("Could not terminate EGL connection" + GetErrorAsString());
eglDisplay = null;
}
glContextAvailable = false;
}
protected void DestroyGLSurface()
{
if (!(eglSurface == null || eglSurface == IEGL10.EglNoSurface))
{
if (!egl.EglMakeCurrent(eglDisplay, IEGL10.EglNoSurface,
IEGL10.EglNoSurface, IEGL10.EglNoContext))
{
Log.Verbose("AndroidGameView", "Could not unbind EGL surface" + GetErrorAsString());
}
if (!egl.EglDestroySurface(eglDisplay, eglSurface))
{View on GitHub (pinned to 1d71bbd0ff)
Solutions
- Ensure all contexts/surfaces are destroyed before terminating the display connection.
- Make EGL resources non-current before teardown to release references.
- Wrap teardown in try/catch so a transient EGL terminate failure does not crash on background/exit.
- On GPU-process loss, recreate the EGL display/connection from scratch.
Example fix
// before
if (!egl.EglTerminate(eglDisplay))
throw new Exception("Could not terminate EGL connection" + GetErrorAsString());
eglDisplay = null;
// after
if (!egl.EglTerminate(eglDisplay))
Debug.WriteLine("EGL terminate failed: " + GetErrorAsString());
eglDisplay = null; Defensive patterns
Strategy: try-catch
Try / catch
try { /* eglTerminate in DestroyGLContext */ }
catch (Exception ex)
{
Debug.WriteLine("EGL terminate failed: " + ex.Message);
} Prevention
- Destroy all contexts/surfaces before terminating the display.
- Make EGL resources non-current first to release references.
- Treat teardown as best-effort to avoid crashes on background.
When it happens
Trigger: DestroyGLContext proceeds to egl.EglTerminate after destroying the context, but the display connection is already invalid, terminated, or there are outstanding contexts/surfaces preventing termination.
Common situations: Teardown ordering issues (other contexts still referencing the display), GPU process crash invalidating the display, or calling DestroyGLContext after the display was already terminated elsewhere.
Related errors
- Could not destroy EGL context
- Could not initialize EGL display
- Could not get EGL display
- Could not get config count.
- No valid EGL configs found
AI-assisted analysis of MonoGame/MonoGame@1d71bbd0ff (2026-08-13).
Data as JSON: /api/errors/c09200bc0d12fc0e.
Report an issue: GitHub.