{"record":{"id":"c2fe07a07e290400","repo":"MonoGame/MonoGame","slug":"could-not-initialize-egl-display","errorCode":null,"errorMessage":"Could not initialize EGL display","messagePattern":"Could not initialize EGL display","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"critical","filePath":"MonoGame.Framework/Platform/Android/MonoGameAndroidGameView.cs","lineNumber":894,"sourceCode":"            public override string ToString()\n            {\n                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);\n            }\n        }\n\n        protected void CreateGLContext()\n        {\n            lostglContext = false;\n\n            egl = EGLContext.EGL.JavaCast<IEGL10>();\n\n            eglDisplay = egl.EglGetDisplay(IEGL10.EglDefaultDisplay);\n            if (eglDisplay == IEGL10.EglNoDisplay)\n                throw new Exception(\"Could not get EGL display\" + GetErrorAsString());\n\n            int[] version = new int[2];\n            if (!egl.EglInitialize(eglDisplay, version))\n                throw new Exception(\"Could not initialize EGL display\" + GetErrorAsString());\n\n            int depth = 0;\n            int stencil = 0;\n            int sampleBuffers = 0;\n            int samples = 0;\n            switch (_game.graphicsDeviceManager.PreferredDepthStencilFormat)\n            {\n                case DepthFormat.Depth16:\n                    depth = 16;\n                    break;\n                case DepthFormat.Depth24:\n                    depth = 24;\n                    break;\n                case DepthFormat.Depth24Stencil8:\n                    depth = 24;\n                    stencil = 8;\n                    break;\n                case DepthFormat.None:","sourceCodeStart":876,"sourceCodeEnd":912,"githubUrl":"https://github.com/MonoGame/MonoGame/blob/1d71bbd0ff4071a03caa583aa3bc56b85924a819/MonoGame.Framework/Platform/Android/MonoGameAndroidGameView.cs#L876-L912","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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).","If EGL_BAD_DISPLAY: ensure no other code path has already initialized this display; audit for duplicate Game instances or GL context leaks.","If EGL_BAD_ALLOC: reduce concurrent GPU usage, close other GPU-heavy apps, or test on a device with more GPU memory.","Retry initialization once after a short delay — transient driver wake-from-sleep issues can resolve on retry.","Update the device's GPU drivers or test on a different device/OS version to rule out an OEM driver bug."],"exampleFix":"// before\nif (!egl.EglInitialize(eglDisplay, version))\n    throw new Exception(\"Could not initialize EGL display\" + GetErrorAsString());\n\n// after — retry once with a log before giving up\nif (!egl.EglInitialize(eglDisplay, version))\n{\n    Log.Warning(\"AndroidGameView\", \"eglInitialize failed ({0}), retrying...\", GetErrorAsString());\n    if (!egl.EglInitialize(eglDisplay, version))\n        throw new Exception(\"Could not initialize EGL display\" + GetErrorAsString());\n}","handlingStrategy":"retry","validationCode":"// Check if the display can be initialized before full game startup\nbool CanInitializeEgl()\n{\n    var egl = EGLContext.EGL.JavaCast<Android.Opengl.IEGL10>();\n    var display = egl.EglGetDisplay(Android.Opengl.IEGL10.EglDefaultDisplay);\n    if (display == Android.Opengl.IEGL10.EglNoDisplay)\n        return false;\n    int[] version = new int[2];\n    return egl.EglInitialize(display, version);\n}","typeGuard":null,"tryCatchPattern":"// Retry eglInitialize once — transient driver wake issues can resolve\nint maxRetries = 1;\nfor (int attempt = 0; attempt <= maxRetries; attempt++)\n{\n    try\n    {\n        // game.Run() or graphics initialization\n        break;\n    }\n    catch (Exception ex) when (ex.Message.Contains(\"Could not initialize EGL display\") && attempt < maxRetries)\n    {\n        Log.Warning(TAG, \"eglInitialize failed, retrying... ({0})\", ex.Message);\n        Thread.Sleep(500);\n    }\n}","preventionTips":["Ensure no other process or Game instance is holding the EGL display.","Avoid creating multiple Game instances on Android.","Close other GPU-intensive apps before testing.","Add a single retry with delay for transient driver wake-from-sleep issues."],"tags":["android","egl","opengl-es","gpu","graphics-initialization","driver","monogame"],"backgroundTag":null,"analyzedSha":"1d71bbd0ff4071a03caa583aa3bc56b85924a819","analyzedAt":"2026-08-13T17:10:33.625Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}