diff --git a/host/gl/glestranslator/egl/egl_surface.cpp b/host/gl/glestranslator/egl/egl_surface.cpp index 49779ae6e..59b57853d 100644 --- a/host/gl/glestranslator/egl/egl_surface.cpp +++ b/host/gl/glestranslator/egl/egl_surface.cpp @@ -18,7 +18,7 @@ #include "egl_display.h" #include "egl_os_api.h" -unsigned int EglSurface::s_nextSurfaceHndl = 0; +std::atomic EglSurface::s_nextSurfaceHndl{0}; EglSurface::~EglSurface(){ diff --git a/host/gl/glestranslator/egl/egl_surface.h b/host/gl/glestranslator/egl/egl_surface.h index f505ddee5..1e9f6bf1a 100644 --- a/host/gl/glestranslator/egl/egl_surface.h +++ b/host/gl/glestranslator/egl/egl_surface.h @@ -22,6 +22,7 @@ #include #include +#include #include class EglSurface; @@ -60,7 +61,9 @@ class EglSurface { GLuint glRboDepth = 0; private: - static unsigned int s_nextSurfaceHndl; + // Atomic: eglCreatePbufferSurface() constructs surfaces before it takes + // graphicsDriverLock(), so two threads can increment it at the same time. + static std::atomic s_nextSurfaceHndl; ESurfaceType m_type = WINDOW; unsigned int m_hndl = 0;