From 82785b91648eb064f77c605f2eb3551c45c19834 Mon Sep 17 00:00:00 2001 From: Okaniku <61146125+okaniku@users.noreply.github.com> Date: Thu, 9 Nov 2023 08:31:41 +1100 Subject: [PATCH] Fix ALC_EXT_EFX hack (#1770) * Fix ALC_EXT_EFX hack * Fix extension loading test --------- Co-authored-by: arcraith --- src/OpenAL/Silk.NET.OpenAL.Tests/ExtensionLoadingTests.cs | 8 ++++++++ src/OpenAL/Silk.NET.OpenAL/AL/AL.cs | 6 ++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/OpenAL/Silk.NET.OpenAL.Tests/ExtensionLoadingTests.cs b/src/OpenAL/Silk.NET.OpenAL.Tests/ExtensionLoadingTests.cs index ea4866f5f6..56cae1c5c9 100644 --- a/src/OpenAL/Silk.NET.OpenAL.Tests/ExtensionLoadingTests.cs +++ b/src/OpenAL/Silk.NET.OpenAL.Tests/ExtensionLoadingTests.cs @@ -31,6 +31,12 @@ public ExtensionLoadingTests(ITestOutputHelper testOutputHelper) [UnmanagedCallersOnly(CallConvs = new []{typeof(CallConvCdecl)})] public static unsafe int AlwaysZero(byte* name) => 0; + [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvCdecl) })] + public static unsafe Context* GetCurrentContext() => null; + + [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvCdecl) })] + public static unsafe Device* GetContextsDevice(Context* ctx) => null; + public unsafe delegate nint LoaderDelegate(byte* name); public unsafe delegate nint ContextLoaderDelegate(void* device, byte* name); @@ -51,6 +57,8 @@ public static unsafe Func GetLoader(bool alwaysPresent, out nint l "alcIsExtensionPresent" or "alIsExtensionPresent" => alwaysPresent ? (nint) (delegate* unmanaged[Cdecl]) &AlwaysOne : (nint) (delegate* unmanaged[Cdecl]) &AlwaysZero, + "alcGetCurrentContext" => (nint) (delegate* unmanaged[Cdecl]) &GetCurrentContext, + "alcGetContextsDevice" => (nint) (delegate* unmanaged[Cdecl]) &GetContextsDevice, "alGetProcAddress" => wrapper[0], "alcGetProcAddress" => wrapper[1], "alGetEnumValue" => (nint) (delegate* unmanaged[Cdecl]) &AlwaysZero, diff --git a/src/OpenAL/Silk.NET.OpenAL/AL/AL.cs b/src/OpenAL/Silk.NET.OpenAL/AL/AL.cs index 2f9049d8ea..275eea7457 100644 --- a/src/OpenAL/Silk.NET.OpenAL/AL/AL.cs +++ b/src/OpenAL/Silk.NET.OpenAL/AL/AL.cs @@ -36,8 +36,10 @@ public override unsafe bool IsExtensionPresent(string name) SilkMarshal.StringIntoSpan(name, nameNative, NativeStringEncoding.UTF8); fixed (byte* namePtr = nameNative) { - return ((delegate* unmanaged[Cdecl]) Context.GetProcAddress("alcIsExtensionPresent")) - (namePtr) == 1; + var currentContext = ((delegate* unmanaged[Cdecl]) Context.GetProcAddress("alcGetCurrentContext"))(); + var currentDevice = ((delegate* unmanaged[Cdecl]) Context.GetProcAddress("alcGetContextsDevice"))(currentContext); + return ((delegate* unmanaged[Cdecl]) Context.GetProcAddress("alcIsExtensionPresent")) + (currentDevice, namePtr) == 1; } }