Repository navigation
Conversation
The EglSurface constructor sets m_hndl = ++s_nextSurfaceHndl. The
counter is a plain unsigned int. eglCreatePbufferSurface() constructs
the surface before it takes graphicsDriverLock(), and ~EglContext()
can construct one outside the lock. Thus, two threads can increment
the counter at the same time and get the same handle.
EglDisplay::addSurface() does not add a surface with a handle that is
already in the map. It returns the existing handle. The second caller
then gets the handle of the first surface, and two emulated window
surfaces share one host surface.
Make the counter std::atomic<unsigned int>.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Fixes #241.
The
EglSurfaceconstructor setsm_hndl = ++s_nextSurfaceHndl. The counter is a plainunsigned int.eglCreatePbufferSurface()constructs the surface before it takesgraphicsDriverLock(). Thus, two threads can get the same handle.EglDisplay::addSurface()thenreturns the handle of the first surface to both callers.
Fix
Make
s_nextSurfaceHndlastd::atomic<unsigned int>.Window surfaces and contexts get their handles while the lock is held. This change does not
modify them.
Test
Windows CMake build with clang-cl, target
EGL_translator_static: completes. We found the race bycode review. We did not see it at run time.
This change was developed with AI assistance (Claude Code; see the
Assisted-bytrailer).