Skip to content

Commit e7f546e

Browse files
author
danwalmsley
authored
Merge pull request AvaloniaUI#3363 from PJB3005/19-12-16-egl
Fix loading EGL functions on GLX.
2 parents 3dbbe6d + fc5ada5 commit e7f546e

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/Avalonia.X11/Glx/Glx.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,24 @@ public delegate IntPtr GlxCreateContextAttribsARB(IntPtr dpy, IntPtr fbconfig, I
8484
[GlEntryPoint("glGetError")]
8585
public GlGetError GetError { get; }
8686

87-
public GlxInterface() : base(GlxGetProcAddress)
87+
public GlxInterface() : base(SafeGetProcAddress)
8888
{
8989
}
90+
91+
// Ignores egl functions.
92+
// On some Linux systems, glXGetProcAddress will return valid pointers for even EGL functions.
93+
// This makes Skia try to load some data from EGL,
94+
// which can then cause segmentation faults because they return garbage.
95+
public static IntPtr SafeGetProcAddress(string proc, bool optional)
96+
{
97+
if (proc.StartsWith("egl", StringComparison.InvariantCulture))
98+
{
99+
return IntPtr.Zero;
100+
}
101+
102+
return GlxConverted(proc, optional);
103+
}
104+
105+
private static readonly Func<string, bool, IntPtr> GlxConverted = ConvertNative(GlxGetProcAddress);
90106
}
91107
}

src/Avalonia.X11/Glx/GlxDisplay.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public GlxDisplay(X11Info x11)
8787
ImmediateContext.MakeCurrent();
8888
var err = Glx.GetError();
8989

90-
GlInterface = new GlInterface(GlxInterface.GlxGetProcAddress);
90+
GlInterface = new GlInterface(GlxInterface.SafeGetProcAddress);
9191
if (GlInterface.Version == null)
9292
throw new OpenGlException("GL version string is null, aborting");
9393
if (GlInterface.Renderer == null)

0 commit comments

Comments
 (0)