Comfy-Org/ComfyUI · error · RuntimeError

eglMakeCurrent() failed (EGL error: 0x{err:04X})

Error message

eglMakeCurrent() failed (EGL error: 0x{err:04X})

What it means

Raised by GLContext.make_current() when re-binding the singleton's surface/context on the calling thread fails, with the raw EGL error code included (e.g. 0x3009 EGL_BAD_MATCH, 0x3006 EGL_BAD_CONTEXT). Unlike the init-time variant, this happens after the context already worked once, so the usual cause is concurrent use from multiple threads or a display/context that was invalidated (GPU reset, driver teardown).

Source

Thrown at comfy_extras/nodes_glsl.py:309

            gl.glBindVertexArray(self._vao)

        except Exception:
            self._cleanup()
            raise

        elapsed = (time.perf_counter() - start) * 1000

        renderer = _gl_str(gl.GL_RENDERER)
        vendor = _gl_str(gl.GL_VENDOR)
        version = _gl_str(gl.GL_VERSION)

        GLContext._initialized = True
        logger.info(f"GLSL context initialized in {elapsed:.1f}ms - EGL {self._egl_major}.{self._egl_minor}, {renderer} ({vendor}), GL {version}")

    def make_current(self):
        if not EGL.eglMakeCurrent(self._display, self._surface, self._surface, self._context):
            err = EGL.eglGetError()
            raise RuntimeError(f"eglMakeCurrent() failed (EGL error: 0x{err:04X})")
        if self._vao is not None:
            gl.glBindVertexArray(self._vao)

    def _cleanup(self):
        if not self._display:
            return
        try:
            if self._vao is not None:
                gl.glDeleteVertexArrays(1, [self._vao])
                self._vao = None
        except Exception:
            pass
        try:
            EGL.eglMakeCurrent(self._display, EGL.EGL_NO_SURFACE, EGL.EGL_NO_SURFACE, EGL.EGL_NO_CONTEXT)
        except Exception:
            pass
        try:
            if self._context:

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Force serial execution of the GLSL nodes (run one at a time; avoid parallel branch execution that fans out into GLSL nodes).
  2. Restart the ComfyUI process to rebuild the singleton GL context after a GPU reset.
  3. Update drivers if EGL_BAD_MATCH / EGL_BAD_ACCESS appears consistently on rebind.
  4. If concurrency is required, route GL work through a single dedicated thread that owns the context.
Defensive patterns

Strategy: retry

Try / catch

try:
    result = run_glsl_node(...)
except RuntimeError as e:
    if "eglMakeCurrent() failed (EGL error" in str(e):
        # context likely invalidated (GPU reset) or raced across threads:
        # serialize GL work and/or restart the process, then retry once
        result = run_glsl_node_serialized(...)
    else:
        raise

Prevention

When it happens

Trigger: Two GLSL nodes (or two worker threads) executing GL work simultaneously so make_current() races on the same context; the context was destroyed by a driver/GPU reset and the singleton still holds stale handles; calling make_current() from a thread where another context is current.

Common situations: Parallel prompt execution in ComfyUI running several GLSL node instances at once; long-running processes that survived a GPU reset.

Related errors


AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14). Data as JSON: /api/errors/004bd3dd406344e3. Report an issue: GitHub.