From d52632b475fbaa7ee3b31e6a330b64e83cf28b6a Mon Sep 17 00:00:00 2001 From: Kevin Yuan Date: Tue, 26 May 2026 13:49:04 +0800 Subject: [PATCH] internal/egl: fix loadEGL caching error on Windows loadEGL used sync.Once incorrectly: the error returned by loadDLLs was assigned to a local variable inside loadEGL, so on the second call Do would not run and the function would return nil even though the DLLs were never loaded. This caused a nil pointer dereference when callers proceeded to use _eglGetDisplay and other uninitialized function pointers. Fix by replacing the sync.Once with sync.OnceValue, which correctly caches the return value of loadDLLs across all calls. Signed-off-by: Kevin Yuan --- internal/egl/egl_windows.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/internal/egl/egl_windows.go b/internal/egl/egl_windows.go index f3cb5292..b6d97eb6 100644 --- a/internal/egl/egl_windows.go +++ b/internal/egl/egl_windows.go @@ -41,14 +41,10 @@ var ( _eglWaitClient *syscall.Proc ) -var loadOnce sync.Once +var loadOnce = sync.OnceValue(loadDLLs) func loadEGL() error { - var err error - loadOnce.Do(func() { - err = loadDLLs() - }) - return err + return loadOnce() } func loadDLLs() error {