From e5241a59e707a7cba8e7c106c36f4a6ead9d1469 Mon Sep 17 00:00:00 2001 From: Steven He Date: Fri, 22 Jul 2022 13:16:38 +0900 Subject: [PATCH 1/2] various fixes --- src/Avalonia.Base/Visual.cs | 10 ++++++++-- src/Avalonia.OpenGL/Controls/OpenGlControlBase.cs | 7 +++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Base/Visual.cs b/src/Avalonia.Base/Visual.cs index 8feba116f09..fbc940114a4 100644 --- a/src/Avalonia.Base/Visual.cs +++ b/src/Avalonia.Base/Visual.cs @@ -667,8 +667,14 @@ private void SetVisualParent(Visual? value) if (_visualParent is IRenderRoot || _visualParent?.IsAttachedToVisualTree == true) { - var root = this.FindAncestorOfType() ?? - throw new AvaloniaInternalException("Visual is atached to visual tree but root could not be found."); + var root = this.FindAncestorOfType(); + if (root is null) + { + Logger.TryGet(LogEventLevel.Error, "Visual")?.Log("Visual", + "Visual is atached to visual tree but root could not be found."); + return; + } + var e = new VisualTreeAttachmentEventArgs(_visualParent, root); OnAttachedToVisualTreeCore(e); } diff --git a/src/Avalonia.OpenGL/Controls/OpenGlControlBase.cs b/src/Avalonia.OpenGL/Controls/OpenGlControlBase.cs index b3469c212b5..ccdc5ac19be 100644 --- a/src/Avalonia.OpenGL/Controls/OpenGlControlBase.cs +++ b/src/Avalonia.OpenGL/Controls/OpenGlControlBase.cs @@ -148,6 +148,13 @@ private bool EnsureInitializedCore() return false; } + if (_context == null) + { + Logger.TryGet(LogEventLevel.Error, "OpenGL")?.Log("OpenGlControlBase", + "Unable to initialize OpenGL: unable to create additional OpenGL context."); + return false; + } + GlVersion = _context.Version; try { From 9377ce2a8fa630de33373d8beda3392d2e1dcb06 Mon Sep 17 00:00:00 2001 From: Steve Date: Sun, 7 Aug 2022 15:23:51 +0900 Subject: [PATCH 2/2] Update Visual.cs --- src/Avalonia.Base/Visual.cs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/Avalonia.Base/Visual.cs b/src/Avalonia.Base/Visual.cs index fbc940114a4..8feba116f09 100644 --- a/src/Avalonia.Base/Visual.cs +++ b/src/Avalonia.Base/Visual.cs @@ -667,14 +667,8 @@ private void SetVisualParent(Visual? value) if (_visualParent is IRenderRoot || _visualParent?.IsAttachedToVisualTree == true) { - var root = this.FindAncestorOfType(); - if (root is null) - { - Logger.TryGet(LogEventLevel.Error, "Visual")?.Log("Visual", - "Visual is atached to visual tree but root could not be found."); - return; - } - + var root = this.FindAncestorOfType() ?? + throw new AvaloniaInternalException("Visual is atached to visual tree but root could not be found."); var e = new VisualTreeAttachmentEventArgs(_visualParent, root); OnAttachedToVisualTreeCore(e); }