From 8c043d5900eef518d2736d2ecffe65a6cb7fadeb Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Mon, 23 Sep 2024 19:28:23 +0200 Subject: [PATCH] Call layer.setNeedsDisplay on show. (#17096) The `AvaloniaNative.GlPlatformSurface.CreateGlRenderTarget` method can only be called on the UI thread. In normal circumstances this method is called in response to a call to `TopLevel.HandlePaint` from the native `AvnView.updateLayer` method. However, a customer was experiencing a problem where `AvnView.updateLayer` and by extension `TopLevel.HandlePaint` were being called before the window is shown. This broke the creation of the GL render target. --- native/Avalonia.Native/src/OSX/WindowBaseImpl.mm | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/native/Avalonia.Native/src/OSX/WindowBaseImpl.mm b/native/Avalonia.Native/src/OSX/WindowBaseImpl.mm index 0335d9e409..2136428db4 100644 --- a/native/Avalonia.Native/src/OSX/WindowBaseImpl.mm +++ b/native/Avalonia.Native/src/OSX/WindowBaseImpl.mm @@ -106,6 +106,13 @@ HRESULT WindowBaseImpl::Show(bool activate, bool isDialog) { _shown = true; [Window setCollectionBehavior:collectionBehavior]; + + // Ensure that we call needsDisplay = YES so that AvnView.updateLayer is called after the + // window is shown: if the client is pumping messages during the window creation/show + // process, it's possible that updateLayer gets called after the window is created but + // before it's is shown. + [View.layer setNeedsDisplay]; + return S_OK; } }