From fb1dcc11b47446ba9b122c2a3b7e60ca11d3000f Mon Sep 17 00:00:00 2001 From: Pieter-Jan Briers Date: Mon, 16 Dec 2019 20:45:52 +0100 Subject: [PATCH 1/2] Fix loading EGL functions on GLX. This fixes apps refusing to run on Arch Linux. --- src/Avalonia.X11/Glx/Glx.cs | 18 +++++++++++++++++- src/Avalonia.X11/Glx/GlxDisplay.cs | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.X11/Glx/Glx.cs b/src/Avalonia.X11/Glx/Glx.cs index c3a2fd2050..a059e92210 100644 --- a/src/Avalonia.X11/Glx/Glx.cs +++ b/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 GlxConverted = ConvertNative(GlxGetProcAddress); } } diff --git a/src/Avalonia.X11/Glx/GlxDisplay.cs b/src/Avalonia.X11/Glx/GlxDisplay.cs index 04f2a7137c..22eb0792e8 100644 --- a/src/Avalonia.X11/Glx/GlxDisplay.cs +++ b/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) From fc5ada5e23dc01610ad59c6407db4c85fc7de8f9 Mon Sep 17 00:00:00 2001 From: Pieter-Jan Briers Date: Tue, 17 Dec 2019 19:13:06 +0100 Subject: [PATCH 2/2] Use invariant culture. --- src/Avalonia.X11/Glx/Glx.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.X11/Glx/Glx.cs b/src/Avalonia.X11/Glx/Glx.cs index a059e92210..714a592f2b 100644 --- a/src/Avalonia.X11/Glx/Glx.cs +++ b/src/Avalonia.X11/Glx/Glx.cs @@ -94,7 +94,7 @@ namespace Avalonia.X11.Glx // which can then cause segmentation faults because they return garbage. public static IntPtr SafeGetProcAddress(string proc, bool optional) { - if (proc.StartsWith("egl")) + if (proc.StartsWith("egl", StringComparison.InvariantCulture)) { return IntPtr.Zero; }