MonoGame/MonoGame · critical · Exception

Could not initialize EGL display

Error message

Could not initialize EGL display

What it means

Thrown when EGL obtained the display handle but eglInitialize failed (returned false). eglInitialize performs internal EGL state setup and negotiates with the GPU driver. Failure here means the driver is present but broken, locked, or in an inconsistent state — distinct from 560 where no display was obtained at all.

Source

Thrown at MonoGame.Framework/Platform/Android/MonoGameAndroidGameView.cs:894

            public override string ToString()
            {
                return string.Format("Red:{0} Green:{1} Blue:{2} Alpha:{3} Depth:{4} Stencil:{5} SampleBuffers:{6} Samples:{7}", Red, Green, Blue, Alpha, Depth, Stencil, SampleBuffers, Samples);
            }
        }

        protected void CreateGLContext()
        {
            lostglContext = false;

            egl = EGLContext.EGL.JavaCast<IEGL10>();

            eglDisplay = egl.EglGetDisplay(IEGL10.EglDefaultDisplay);
            if (eglDisplay == IEGL10.EglNoDisplay)
                throw new Exception("Could not get EGL display" + GetErrorAsString());

            int[] version = new int[2];
            if (!egl.EglInitialize(eglDisplay, version))
                throw new Exception("Could not initialize EGL display" + GetErrorAsString());

            int depth = 0;
            int stencil = 0;
            int sampleBuffers = 0;
            int samples = 0;
            switch (_game.graphicsDeviceManager.PreferredDepthStencilFormat)
            {
                case DepthFormat.Depth16:
                    depth = 16;
                    break;
                case DepthFormat.Depth24:
                    depth = 24;
                    break;
                case DepthFormat.Depth24Stencil8:
                    depth = 24;
                    stencil = 8;
                    break;
                case DepthFormat.None:

View on GitHub (pinned to 1d71bbd0ff)

Solutions

  1. Check GetErrorAsString() output (appended to the message) — eglGetError will report EGL_BAD_DISPLAY (display already in use), EGL_NOT_INITIALIZED, or EGL_BAD_ALLOC (resource exhaustion).
  2. If EGL_BAD_DISPLAY: ensure no other code path has already initialized this display; audit for duplicate Game instances or GL context leaks.
  3. If EGL_BAD_ALLOC: reduce concurrent GPU usage, close other GPU-heavy apps, or test on a device with more GPU memory.
  4. Retry initialization once after a short delay — transient driver wake-from-sleep issues can resolve on retry.
  5. Update the device's GPU drivers or test on a different device/OS version to rule out an OEM driver bug.

Example fix

// before
if (!egl.EglInitialize(eglDisplay, version))
    throw new Exception("Could not initialize EGL display" + GetErrorAsString());

// after — retry once with a log before giving up
if (!egl.EglInitialize(eglDisplay, version))
{
    Log.Warning("AndroidGameView", "eglInitialize failed ({0}), retrying...", GetErrorAsString());
    if (!egl.EglInitialize(eglDisplay, version))
        throw new Exception("Could not initialize EGL display" + GetErrorAsString());
}
Defensive patterns

Strategy: retry

Validate before calling

// Check if the display can be initialized before full game startup
bool CanInitializeEgl()
{
    var egl = EGLContext.EGL.JavaCast<Android.Opengl.IEGL10>();
    var display = egl.EglGetDisplay(Android.Opengl.IEGL10.EglDefaultDisplay);
    if (display == Android.Opengl.IEGL10.EglNoDisplay)
        return false;
    int[] version = new int[2];
    return egl.EglInitialize(display, version);
}

Try / catch

// Retry eglInitialize once — transient driver wake issues can resolve
int maxRetries = 1;
for (int attempt = 0; attempt <= maxRetries; attempt++)
{
    try
    {
        // game.Run() or graphics initialization
        break;
    }
    catch (Exception ex) when (ex.Message.Contains("Could not initialize EGL display") && attempt < maxRetries)
    {
        Log.Warning(TAG, "eglInitialize failed, retrying... ({0})", ex.Message);
        Thread.Sleep(500);
    }
}

Prevention

When it happens

Trigger: Called from CreateGLContext() immediately after a successful eglGetDisplay. egl.EglInitialize(eglDisplay, version) returns false. The display handle is valid but the driver cannot complete initialization.

Common situations: GPU driver crash from a prior process that left the driver in a bad state. Device waking from sleep with GPU in a low-power state that isn't fully resumed. Multiple EGL initializations on the same display without proper teardown. Out-of-memory on the GPU side. Conflicting GL contexts from other apps exhausting driver resources. Bug in a specific OEM driver build.

Related errors


AI-assisted analysis of MonoGame/MonoGame@1d71bbd0ff (2026-08-13). Data as JSON: /api/errors/c2fe07a07e290400. Report an issue: GitHub.