Skip to content

Commit

Permalink
Merge pull request AvaloniaUI#3363 from PJB3005/19-12-16-egl
Browse files Browse the repository at this point in the history
Fix loading EGL functions on GLX.
  • Loading branch information
danwalmsley authored Dec 17, 2019
2 parents 3dbbe6d + fc5ada5 commit e7f546e
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", StringComparison.InvariantCulture))
{
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 e7f546e

Please sign in to comment.