浏览代码

Fix loading EGL functions on GLX.

This fixes apps refusing to run on Arch Linux.
Pieter-Jan Briers 6 年之前
父节点
当前提交
fb1dcc11b4
共有 2 个文件被更改,包括 18 次插入2 次删除
  1. 17 1
      src/Avalonia.X11/Glx/Glx.cs
  2. 1 1
      src/Avalonia.X11/Glx/GlxDisplay.cs

+ 17 - 1
src/Avalonia.X11/Glx/Glx.cs

@@ -84,8 +84,24 @@ namespace Avalonia.X11.Glx
         [GlEntryPoint("glGetError")]
         public GlGetError GetError { get; }
 
-        public GlxInterface() : base(GlxGetProcAddress)
+        public GlxInterface() : base(SafeGetProcAddress)
         {
         }
+
+        // Ignores egl functions.
+        // On some Linux systems, glXGetProcAddress will return valid pointers for even EGL functions.
+        // This makes Skia try to load some data from EGL,
+        // which can then cause segmentation faults because they return garbage.
+        public static IntPtr SafeGetProcAddress(string proc, bool optional)
+        {
+            if (proc.StartsWith("egl"))
+            {
+                return IntPtr.Zero;
+            }
+
+            return GlxConverted(proc, optional);
+        }
+
+        private static readonly Func<string, bool, IntPtr> GlxConverted = ConvertNative(GlxGetProcAddress);
     }
 }

+ 1 - 1
src/Avalonia.X11/Glx/GlxDisplay.cs

@@ -87,7 +87,7 @@ namespace Avalonia.X11.Glx
             ImmediateContext.MakeCurrent();
             var err = Glx.GetError();
             
-            GlInterface = new GlInterface(GlxInterface.GlxGetProcAddress);
+            GlInterface = new GlInterface(GlxInterface.SafeGetProcAddress);
             if (GlInterface.Version == null)
                 throw new OpenGlException("GL version string is null, aborting");
             if (GlInterface.Renderer == null)