Skip to content

Commit

Permalink
Fix loading EGL functions on GLX.
Browse files Browse the repository at this point in the history
This fixes apps refusing to run on Arch Linux.
  • Loading branch information
PJB3005 committed Dec 16, 2019
1 parent 3dbbe6d commit fb1dcc1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
18 changes: 17 additions & 1 deletion src/Avalonia.X11/Glx/Glx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,24 @@ public delegate IntPtr GlxCreateContextAttribsARB(IntPtr dpy, IntPtr fbconfig, I
[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);
}
}
2 changes: 1 addition & 1 deletion src/Avalonia.X11/Glx/GlxDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public GlxDisplay(X11Info x11)
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)
Expand Down

0 comments on commit fb1dcc1

Please sign in to comment.