From 06fdb648ac1405048d95ffe0317ea5a66a9c8ac5 Mon Sep 17 00:00:00 2001 From: AB901 <44526542+AB901@users.noreply.github.com> Date: Fri, 24 Jul 2026 23:20:34 +0800 Subject: [PATCH] Fix EGL surface recreation after native handle changes (#21816) Co-authored-by: Julien Lebosquain --- src/Avalonia.OpenGL/Egl/EglGlPlatformSurface.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Avalonia.OpenGL/Egl/EglGlPlatformSurface.cs b/src/Avalonia.OpenGL/Egl/EglGlPlatformSurface.cs index 5afe87f4a4..900edf7f58 100644 --- a/src/Avalonia.OpenGL/Egl/EglGlPlatformSurface.cs +++ b/src/Avalonia.OpenGL/Egl/EglGlPlatformSurface.cs @@ -40,7 +40,7 @@ namespace Avalonia.OpenGL.Egl private EglSurface? _glSurface; private readonly IEglWindowGlPlatformSurfaceInfo _info; private PixelSize _currentSize; - private readonly IntPtr _handle; + private IntPtr _handle; public RenderTarget(EglSurface glSurface, EglContext context, IEglWindowGlPlatformSurfaceInfo info) : base(context) { @@ -58,16 +58,19 @@ namespace Avalonia.OpenGL.Egl public override IGlPlatformSurfaceRenderingSession BeginDrawCore(IRenderTarget.RenderTargetSceneInfo sceneInfo) { // TODO: use expectedPixelSize - if (_info.Size != _currentSize - || _handle != _info.Handle + var handle = _info.Handle; + var size = _info.Size; + if (size != _currentSize + || _handle != handle || _glSurface == null) { _glSurface?.Dispose(); _glSurface = null; - _glSurface = Context.Display.CreateWindowSurface(_info.Handle); - _currentSize = _info.Size; + _glSurface = Context.Display.CreateWindowSurface(handle); + _currentSize = size; + _handle = handle; } - return base.BeginDraw(_glSurface, _info.Size, _info.Scaling); + return base.BeginDraw(_glSurface, size, _info.Scaling); } } }