Skip to content

egl: handle a NULL pbuffer in WGL createPbufferSurface() - #248

Open
RieBi wants to merge 1 commit into
google:mainfrom
RieBi:wgl-pbuffer-null-create
Open

RieBi wants to merge 1 commit into
google:mainfrom
RieBi:wgl-pbuffer-null-create

Conversation

@RieBi

@RieBi RieBi commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Problem

Fixes #247.

WglDisplay::createPbufferSurface() does not check the result of createPbufferSurfaceImpl().
That function returns NULL when wglCreatePbuffer is not available or fails.

  1. The refill loop pushes a NULL result into mFreePbufs. Then the code calls refreshDC() on
    freeElts.back(). If that entry is NULL, this dereferences NULL.
  2. After a failed refreshDC(), the replacement can also be NULL. The code inserts it into
    mLivePbufs and returns it.

createPbufferSurfaceImpl() also drops the GetLastError() code, so the failure is not logged.

Fix

  1. Stop the refill at the first NULL result. The causes of a NULL result persist, so the next
    calls fail too.
  2. If the free list is still empty after the refill, return NULL.
  3. If the replacement after a failed refreshDC() is NULL, return NULL. Do not insert it into
    mLivePbufs. The old pbuffer stays in mDeletePbufs, as before.
  4. Log a failed wglCreatePbuffer with its error code: the first 8 failures, then at powers of
    two. The new shouldLogFailure() holds this rule. releasePbuffer() used the same rule inline
    (egl: return WGL pbuffers to the pool when DC release fails #239) and now calls it.

Both callers already check for NULL: eglCreatePbufferSurface() sets EGL_BAD_ATTRIBUTE and
returns EGL_NO_SURFACE, and ~EglContext skips the makeCurrent() (debug builds stop at its
assert). The GLX backend does not change: its createPbufferSurfaceImpl() never returns NULL.

Test

Windows CMake build with clang-cl, target EGL_translator_static: completes. We found this by code
review. We did not see it occur.

This change was developed with AI assistance (Claude Code; see the Assisted-by trailer).

createPbufferSurfaceImpl() returns NULL when wglCreatePbuffer is not
available or fails. createPbufferSurface() pushed that NULL into the
free list and then called refreshDC() on it. A NULL replacement after
a failed refreshDC() went into mLivePbufs and back to the caller.

Stop the refill at the first NULL result: a missing function or an
out-of-resources driver makes the next calls fail too. Return NULL
when the refill creates no pbuffer, or when the replacement is NULL.
Both callers already check for NULL.

Log a failed wglCreatePbuffer with its error code, at the same rate
as the wglReleasePbufferDC warning. Move that rate rule into
shouldLogFailure() for both.

Test: Windows CMake build with clang-cl, target EGL_translator_static.
      Found by code review; not seen at run time.

Assisted-by: Claude Code:Claude-Opus-5.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WGL: createPbufferSurface() does not handle a NULL pbuffer

1 participant