From a4d3afd06d63059ca2b2cff0b4fb2577dd74818e Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 7 Apr 2022 19:12:10 +0900 Subject: [PATCH] Fix multiple issues with bindable safety in `SkinEditor` components --- .../Skinning/Editor/SkinBlueprintContainer.cs | 23 ++++++++++++------- osu.Game/Skinning/Editor/SkinEditor.cs | 3 +++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/osu.Game/Skinning/Editor/SkinBlueprintContainer.cs b/osu.Game/Skinning/Editor/SkinBlueprintContainer.cs index d67bfb89ab..ebf3c9c319 100644 --- a/osu.Game/Skinning/Editor/SkinBlueprintContainer.cs +++ b/osu.Game/Skinning/Editor/SkinBlueprintContainer.cs @@ -21,21 +21,20 @@ namespace osu.Game.Skinning.Editor private readonly List> targetComponents = new List>(); + [Resolved] + private SkinEditor editor { get; set; } + public SkinBlueprintContainer(Drawable target) { this.target = target; } - [BackgroundDependencyLoader(true)] - private void load(SkinEditor editor) - { - SelectedItems.BindTo(editor.SelectedComponents); - } - protected override void LoadComplete() { base.LoadComplete(); + SelectedItems.BindTo(editor.SelectedComponents); + // track each target container on the current screen. var targetContainers = target.ChildrenOfType().ToArray(); @@ -56,7 +55,7 @@ namespace osu.Game.Skinning.Editor } } - private void componentsChanged(object sender, NotifyCollectionChangedEventArgs e) + private void componentsChanged(object sender, NotifyCollectionChangedEventArgs e) => Schedule(() => { switch (e.Action) { @@ -79,7 +78,7 @@ namespace osu.Game.Skinning.Editor AddBlueprintFor(item); break; } - } + }); protected override void AddBlueprintFor(ISkinnableDrawable item) { @@ -93,5 +92,13 @@ namespace osu.Game.Skinning.Editor protected override SelectionBlueprint CreateBlueprintFor(ISkinnableDrawable component) => new SkinBlueprint(component); + + protected override void Dispose(bool isDisposing) + { + base.Dispose(isDisposing); + + foreach (var list in targetComponents) + list.UnbindAll(); + } } } diff --git a/osu.Game/Skinning/Editor/SkinEditor.cs b/osu.Game/Skinning/Editor/SkinEditor.cs index bcff70c008..4602366413 100644 --- a/osu.Game/Skinning/Editor/SkinEditor.cs +++ b/osu.Game/Skinning/Editor/SkinEditor.cs @@ -203,6 +203,9 @@ namespace osu.Game.Skinning.Editor SelectedComponents.Clear(); + // Immediately clear the previous blueprint container to ensure it doesn't try to interact with the old target. + content.Clear(); + Scheduler.AddOnce(loadBlueprintContainer); Scheduler.AddOnce(populateSettings);