1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 12:07:23 +08:00

Merge pull request #16278 from peppy/fix-skin-editor-overlay-show-thread-safetyu

Fix calling `SkinEditorOverlay.Show` before the overlay is loaded causing an exception
This commit is contained in:
Bartłomiej Dach 2022-01-03 20:41:48 +01:00 committed by GitHub
commit 8f335c333c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,7 +1,6 @@
// 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.
using System.Diagnostics;
using JetBrains.Annotations;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
@ -67,18 +66,34 @@ namespace osu.Game.Skinning.Editor
public override void Show()
{
// base call intentionally omitted.
if (skinEditor == null)
// base call intentionally omitted as we have custom behaviour.
if (skinEditor != null)
{
skinEditor = new SkinEditor(target);
skinEditor.State.BindValueChanged(editorVisibilityChanged);
Debug.Assert(skinEditor != null);
LoadComponentAsync(skinEditor, AddInternal);
}
else
skinEditor.Show();
return;
}
var editor = new SkinEditor(target);
editor.State.BindValueChanged(editorVisibilityChanged);
skinEditor = editor;
// Schedule ensures that if `Show` is called before this overlay is loaded,
// it will not throw (LoadComponentAsync requires the load target to be in a loaded state).
Schedule(() =>
{
if (editor != skinEditor)
return;
LoadComponentAsync(editor, _ =>
{
if (editor != skinEditor)
return;
AddInternal(editor);
});
});
}
private void editorVisibilityChanged(ValueChangedEvent<Visibility> visibility)