From c5b7e97bd9bde610074c8f529d30f347083a8003 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 29 Sep 2021 18:50:55 +0900 Subject: [PATCH] Fix skin editor potentially crashing during close process As reported at https://github.com/ppy/osu/discussions/14850#discussioncomment-1399382. --- osu.Game/Skinning/Editor/SkinEditorOverlay.cs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/osu.Game/Skinning/Editor/SkinEditorOverlay.cs b/osu.Game/Skinning/Editor/SkinEditorOverlay.cs index a892ec1ca3..2b25ccbe87 100644 --- a/osu.Game/Skinning/Editor/SkinEditorOverlay.cs +++ b/osu.Game/Skinning/Editor/SkinEditorOverlay.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System.Diagnostics; +using JetBrains.Annotations; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; @@ -20,6 +22,8 @@ namespace osu.Game.Skinning.Editor public class SkinEditorOverlay : CompositeDrawable, IKeyBindingHandler { private readonly ScalingContainer target; + + [CanBeNull] private SkinEditor skinEditor; public const float VISIBLE_TARGET_SCALE = 0.8f; @@ -62,6 +66,8 @@ namespace osu.Game.Skinning.Editor public override void Hide() { + Debug.Assert(skinEditor != null); + // base call intentionally omitted. skinEditor.Hide(); } @@ -71,8 +77,12 @@ namespace osu.Game.Skinning.Editor // base call intentionally omitted. if (skinEditor == null) { - LoadComponentAsync(skinEditor = new SkinEditor(target), AddInternal); + skinEditor = new SkinEditor(target); skinEditor.State.BindValueChanged(editorVisibilityChanged); + + Debug.Assert(skinEditor != null); + + LoadComponentAsync(skinEditor, AddInternal); } else skinEditor.Show(); @@ -98,8 +108,13 @@ namespace osu.Game.Skinning.Editor } } - private void updateMasking() => + private void updateMasking() + { + if (skinEditor == null) + return; + target.Masking = skinEditor.State.Value == Visibility.Visible; + } public void OnReleased(KeyBindingReleaseEvent e) {