From 7983a496e37be5b980557263df8be959ba8af0fa Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Sat, 18 Dec 2021 22:25:09 +0100 Subject: [PATCH] Fix mistakes made when adding nullable annotations. I shouldn't be doing this stuff when I'm tired. --- src/Avalonia.Visuals/Media/DrawingContext.cs | 4 +-- .../SceneGraph/DeferredDrawingContextImpl.cs | 25 +++++++++++-------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/Avalonia.Visuals/Media/DrawingContext.cs b/src/Avalonia.Visuals/Media/DrawingContext.cs index a2e3bdc6aa..2fbef8c89f 100644 --- a/src/Avalonia.Visuals/Media/DrawingContext.cs +++ b/src/Avalonia.Visuals/Media/DrawingContext.cs @@ -297,10 +297,10 @@ namespace Avalonia.Media public void Dispose() { - if (_context._states is null || _context._transformContainers is null) - throw new ObjectDisposedException(nameof(DrawingContext)); if (_type == PushedStateType.None) return; + if (_context._states is null || _context._transformContainers is null) + throw new ObjectDisposedException(nameof(DrawingContext)); if (_context._currentLevel != _level) throw new InvalidOperationException("Wrong Push/Pop state order"); _context._currentLevel--; diff --git a/src/Avalonia.Visuals/Rendering/SceneGraph/DeferredDrawingContextImpl.cs b/src/Avalonia.Visuals/Rendering/SceneGraph/DeferredDrawingContextImpl.cs index 934d2666b4..688cbd83c8 100644 --- a/src/Avalonia.Visuals/Rendering/SceneGraph/DeferredDrawingContextImpl.cs +++ b/src/Avalonia.Visuals/Rendering/SceneGraph/DeferredDrawingContextImpl.cs @@ -48,18 +48,21 @@ namespace Avalonia.Rendering.SceneGraph /// public UpdateState BeginUpdate(VisualNode node) { - _ = _node ?? throw new ArgumentNullException(nameof(node)); + _ = node ?? throw new ArgumentNullException(nameof(node)); - if (_childIndex < _node.Children.Count) + if (_node != null) { - _node.ReplaceChild(_childIndex, node); - } - else - { - _node.AddChild(node); - } + if (_childIndex < _node.Children.Count) + { + _node.ReplaceChild(_childIndex, node); + } + else + { + _node.AddChild(node); + } - ++_childIndex; + ++_childIndex; + } var state = new UpdateState(this, _node, _childIndex, _drawOperationindex); _node = node; @@ -406,7 +409,7 @@ namespace Avalonia.Rendering.SceneGraph { public UpdateState( DeferredDrawingContextImpl owner, - VisualNode node, + VisualNode? node, int childIndex, int drawOperationIndex) { @@ -436,7 +439,7 @@ namespace Avalonia.Rendering.SceneGraph } public DeferredDrawingContextImpl Owner { get; } - public VisualNode Node { get; } + public VisualNode? Node { get; } public int ChildIndex { get; } public int DrawOperationIndex { get; } }