Merge pull request #14890 from peppy/skin-editor-nullable-allowed

Fix skin editor potentially crashing during close process
This commit is contained in:
Dan Balasescu
2021-09-29 20:19:19 +09:00
committed by GitHub
2 changed files with 16 additions and 4 deletions

View File

@ -22,7 +22,6 @@ using Humanizer;
using JetBrains.Annotations; using JetBrains.Annotations;
using osu.Framework.Audio; using osu.Framework.Audio;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Development;
using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Input; using osu.Framework.Input;

View File

@ -1,6 +1,8 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // 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.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -20,6 +22,8 @@ namespace osu.Game.Skinning.Editor
public class SkinEditorOverlay : CompositeDrawable, IKeyBindingHandler<GlobalAction> public class SkinEditorOverlay : CompositeDrawable, IKeyBindingHandler<GlobalAction>
{ {
private readonly ScalingContainer target; private readonly ScalingContainer target;
[CanBeNull]
private SkinEditor skinEditor; private SkinEditor skinEditor;
public const float VISIBLE_TARGET_SCALE = 0.8f; public const float VISIBLE_TARGET_SCALE = 0.8f;
@ -63,7 +67,7 @@ namespace osu.Game.Skinning.Editor
public override void Hide() public override void Hide()
{ {
// base call intentionally omitted. // base call intentionally omitted.
skinEditor.Hide(); skinEditor?.Hide();
} }
public override void Show() public override void Show()
@ -71,8 +75,12 @@ namespace osu.Game.Skinning.Editor
// base call intentionally omitted. // base call intentionally omitted.
if (skinEditor == null) if (skinEditor == null)
{ {
LoadComponentAsync(skinEditor = new SkinEditor(target), AddInternal); skinEditor = new SkinEditor(target);
skinEditor.State.BindValueChanged(editorVisibilityChanged); skinEditor.State.BindValueChanged(editorVisibilityChanged);
Debug.Assert(skinEditor != null);
LoadComponentAsync(skinEditor, AddInternal);
} }
else else
skinEditor.Show(); skinEditor.Show();
@ -98,8 +106,13 @@ namespace osu.Game.Skinning.Editor
} }
} }
private void updateMasking() => private void updateMasking()
{
if (skinEditor == null)
return;
target.Masking = skinEditor.State.Value == Visibility.Visible; target.Masking = skinEditor.State.Value == Visibility.Visible;
}
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e) public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
{ {