From ae7a532d068633e4043351f625a7500afb959298 Mon Sep 17 00:00:00 2001 From: Emmanuel Hansen Date: Thu, 10 Nov 2022 14:19:23 +0000 Subject: [PATCH 1/2] do not create a surface if the window provided is invalid --- src/Avalonia.OpenGL/Egl/EglPlatformOpenGlInterface.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Avalonia.OpenGL/Egl/EglPlatformOpenGlInterface.cs b/src/Avalonia.OpenGL/Egl/EglPlatformOpenGlInterface.cs index a6d8c1e98d..04ea29a507 100644 --- a/src/Avalonia.OpenGL/Egl/EglPlatformOpenGlInterface.cs +++ b/src/Avalonia.OpenGL/Egl/EglPlatformOpenGlInterface.cs @@ -50,6 +50,8 @@ namespace Avalonia.OpenGL.Egl { using (PrimaryContext.MakeCurrent()) { + if(window == IntPtr.Zero) + throw new OpenGlException($"Window {window} is invalid."); var s = Display.EglInterface.CreateWindowSurface(Display.Handle, Display.Config, window, new[] { EGL_NONE, EGL_NONE }); if (s == IntPtr.Zero) From 8f6e9f1d0d9b1cae54a2cce2b3f3418b2949e4a3 Mon Sep 17 00:00:00 2001 From: Emmanuel Hansen Date: Thu, 10 Nov 2022 15:01:12 +0000 Subject: [PATCH 2/2] move check before MakeCurrent --- src/Avalonia.OpenGL/Egl/EglPlatformOpenGlInterface.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Avalonia.OpenGL/Egl/EglPlatformOpenGlInterface.cs b/src/Avalonia.OpenGL/Egl/EglPlatformOpenGlInterface.cs index 04ea29a507..a1ac2a9d37 100644 --- a/src/Avalonia.OpenGL/Egl/EglPlatformOpenGlInterface.cs +++ b/src/Avalonia.OpenGL/Egl/EglPlatformOpenGlInterface.cs @@ -44,14 +44,15 @@ namespace Avalonia.OpenGL.Egl public IGlContext CreateContext() => Display.CreateContext(null); public IGlContext CreateSharedContext() => Display.CreateContext(PrimaryEglContext); - + public EglSurface CreateWindowSurface(IntPtr window) { + if (window == IntPtr.Zero) + throw new OpenGlException($"Window {window} is invalid."); + using (PrimaryContext.MakeCurrent()) { - if(window == IntPtr.Zero) - throw new OpenGlException($"Window {window} is invalid."); var s = Display.EglInterface.CreateWindowSurface(Display.Handle, Display.Config, window, new[] { EGL_NONE, EGL_NONE }); if (s == IntPtr.Zero)