From 75d2802ae6d16b6534717dcacc01a2b7f53ba1a9 Mon Sep 17 00:00:00 2001 From: Morilli <35152647+Morilli@users.noreply.github.com> Date: Wed, 6 Aug 2025 09:19:32 +0200 Subject: [PATCH] Fix NRE in WGL IsExtensionPresent `_extensions` was always null, so this always threw an exception --- src/OpenGL/Silk.NET.WGL/WGL.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/OpenGL/Silk.NET.WGL/WGL.cs b/src/OpenGL/Silk.NET.WGL/WGL.cs index 888a08508e..7047093fec 100644 --- a/src/OpenGL/Silk.NET.WGL/WGL.cs +++ b/src/OpenGL/Silk.NET.WGL/WGL.cs @@ -41,20 +41,20 @@ public bool TryGetExtension(out T ext, nint hdc) public override bool IsExtensionPresent(string extension) => IsExtensionPresent(extension, GetCurrentDC()); - private ConcurrentDictionary> _extensions; + private readonly ConcurrentDictionary> _extensions = new(); [NativeApi(EntryPoint = "wglGetExtensionsStringARB")] private partial string GetExtensionsString(nint hdc); - private static HashSet? _empty; + private static readonly HashSet _empty = new(); private bool _hasGetExtensionsString; public bool IsExtensionPresent(string extension, nint hdc) => _extensions.GetOrAdd ( hdc, hdc => !(_hasGetExtensionsString = _hasGetExtensionsString || GetProcAddress("wglGetExtensionsStringARB") != 0) - ? _empty ??= new HashSet() - : new HashSet(GetExtensionsString(hdc).Split(' ')) + ? _empty + : new HashSet(GetExtensionsString(hdc).Split(' ')) ) .Contains(extension.StartsWith("WGL_") ? extension : $"WGL_{extension}"); }