Skip to content

Commit ec351a6

Browse files
authored
Fix NRE in WGL IsExtensionPresent (#2470)
`_extensions` was always null, so this always threw an exception
1 parent 1fc3e6b commit ec351a6

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/OpenGL/Silk.NET.WGL/WGL.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,20 @@ public bool TryGetExtension<T>(out T ext, nint hdc)
4141

4242
public override bool IsExtensionPresent(string extension) => IsExtensionPresent(extension, GetCurrentDC());
4343

44-
private ConcurrentDictionary<nint, HashSet<string>> _extensions;
44+
private readonly ConcurrentDictionary<nint, HashSet<string>> _extensions = new();
4545

4646
[NativeApi(EntryPoint = "wglGetExtensionsStringARB")]
4747
private partial string GetExtensionsString(nint hdc);
4848

49-
private static HashSet<string>? _empty;
49+
private static readonly HashSet<string> _empty = new();
5050
private bool _hasGetExtensionsString;
5151

5252
public bool IsExtensionPresent(string extension, nint hdc) => _extensions.GetOrAdd
5353
(
5454
hdc, hdc => !(_hasGetExtensionsString =
5555
_hasGetExtensionsString || GetProcAddress("wglGetExtensionsStringARB") != 0)
56-
? _empty ??= new HashSet<string>()
57-
: new HashSet<string>(GetExtensionsString(hdc).Split(' '))
56+
? _empty
57+
: new HashSet<string>(GetExtensionsString(hdc).Split(' '))
5858
)
5959
.Contains(extension.StartsWith("WGL_") ? extension : $"WGL_{extension}");
6060
}

0 commit comments

Comments
 (0)