From dad348111d2be5c53d73b8694a378bb81f6be9c2 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 7 Feb 2023 16:07:33 +0900 Subject: [PATCH] Fix holding a selection while changing screens causing a crash --- osu.Game/Overlays/SkinEditor/SkinEditor.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/osu.Game/Overlays/SkinEditor/SkinEditor.cs b/osu.Game/Overlays/SkinEditor/SkinEditor.cs index ad031d2c7e..0716505f26 100644 --- a/osu.Game/Overlays/SkinEditor/SkinEditor.cs +++ b/osu.Game/Overlays/SkinEditor/SkinEditor.cs @@ -481,8 +481,16 @@ namespace osu.Game.Overlays.SkinEditor remove => throw new NotImplementedException(); } - public void BeginChange() => changeHandler?.BeginChange(); - public void EndChange() => changeHandler?.EndChange(); + private IEditorChangeHandler? beginChangeHandler; + + public void BeginChange() + { + // Change handler may change between begin and end, which can cause unbalanced operations. + // Let's track the one that was used when beginning the change so we can call EndChange on it specifically. + (beginChangeHandler = changeHandler)?.BeginChange(); + } + + public void EndChange() => beginChangeHandler?.EndChange(); public void SaveState() => changeHandler?.SaveState(); #endregion