From bb1598deb608ee8f661ebe2b3edf2bf0c099898d Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Mon, 18 May 2026 22:34:42 +0500 Subject: [PATCH] [EGL] Use eglGetProcAddress instead of NativeLibrary.TryGetExport (#21392) --- src/Avalonia.OpenGL/Egl/EglInterface.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.OpenGL/Egl/EglInterface.cs b/src/Avalonia.OpenGL/Egl/EglInterface.cs index 492c646da2..d158cb6543 100644 --- a/src/Avalonia.OpenGL/Egl/EglInterface.cs +++ b/src/Avalonia.OpenGL/Egl/EglInterface.cs @@ -1,5 +1,6 @@ using System; using System.Runtime.InteropServices; +using System.Text; using Avalonia.SourceGenerator; namespace Avalonia.OpenGL.Egl @@ -33,7 +34,16 @@ namespace Avalonia.OpenGL.Egl static Func Load(string library) { var lib = NativeLibrary.Load(library); - return (s) => NativeLibrary.TryGetExport(lib, s, out var address) ? address : default; + NativeLibrary.TryGetExport(lib, "eglGetProcAddress", out var getProcAddress); + if (getProcAddress == IntPtr.Zero) + throw new OpenGlException($"{library} doesn't expose eglGetProcAddress"); + return s => + { + var bytes = new byte[Encoding.UTF8.GetByteCount(s) + 1]; + Encoding.UTF8.GetBytes(s, bytes.AsSpan().Slice(0, bytes.Length - 1)); + fixed (byte* ptr = bytes) + return ((delegate* unmanaged[Stdcall])getProcAddress)(ptr); + }; } // ReSharper disable UnassignedGetOnlyAutoProperty